我想使用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.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“status”。现在我想将相同的值发送到另一个PHP页面test.php,并在同一个函数名下的id“test”中返回结果
答案 0 :(得分:0)
你可以使用
localStorage或cookies来存储变量值
和
从网址传递状态