如何将变量传递到两个不同的php页面
我想使用jQuery将提交的值传递给两个不同的PHP页面,并返回结果。我试过下面的代码如何将变量传递到两个不同的php页面,php,jquery,Php,Jquery,我想使用jQuery将提交的值传递给两个不同的PHP页面,并返回结果。我试过下面的代码 function showOutput(){ // Create our XMLHttpRequest object var hr = new XMLHttpRequest(); // Create some variables we need to send to our PHP file var url = "result.php"; var bb = document
function showOutput(){
// Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var url = "result.php";
var bb = document.getElementById("bankbranch").value;
var bs = document.getElementById("bankstate").value;
var bd = document.getElementById("bankdist").value;
var bn = document.getElementById("bankname").value;
var vars = "bankbranch="+bb+"&bankstate="+bs+"&bankdist="+bd+"&bankname="+bn;
hr.open("POST", url, true);
// Set content type header information for sending url encoded variables in the request
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// Access the onreadystatechange event for the XMLHttpRequest object
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}
}
// Send the data to PHP now... and wait for response to update the status div
hr.send(vars); // Actually execute the request
document.getElementById("status").innerHTML = "Processing...";
}
它将值发送到result.php并以id状态获取结果。现在,我想将相同的值发送到另一个PHP页面test.PHP,并在id test中以您可以使用的相同函数名返回结果
用于存储变量值的localStorage或Cookie
及
从url传递状态为什么不使用jQuery的Ajax方法?这与php有什么关系?您应该删除该标记,因为后端是php、java还是其他任何东西都是一样的。php是服务器端,Javascript是客户端,您认为如何实现这一点?实现这一点的唯一方法是让两个PHP脚本共享一个全局变量,由其中一个在某种Ajax调用中设置。