Right now I have this:
现在我有这个:
var ajax = getRequest();
ajax.onreadystatechange = function(){
if(ajax.readyState == 4){
document.getElementById('results').innerHTML = ajax.responseText;
}
}
ajax.open("GET", "get_schedule.php", true);
ajax.send(null);
}
function getRequest() {
var req = false;
try{
// most browsers
req = new XMLHttpRequest();
} catch (e){
// IE
try{
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
// try an older version
try{
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
return false;
}
}
}
return req;
}
which allows me to call a php file with code get_schedule.php. However I would like to pass a variable along with the ajax function. I am pretty new to Ajax, so how would I do this?
这允许我用代码get_schedule.php调用一个php文件。但是我想传递一个变量和ajax函数。我对Ajax很新,所以我该怎么做?
1 个解决方案
#1
0
Since you're using GET
, you pass parameters by appending them to the URL:
由于您正在使用GET,因此您可以通过将参数附加到URL来传递参数:
ajax.open("GET", "get_schedule.php?paramname=" + encodeURIComponent(paramvalue), true);
#1
0
Since you're using GET
, you pass parameters by appending them to the URL:
由于您正在使用GET,因此您可以通过将参数附加到URL来传递参数:
ajax.open("GET", "get_schedule.php?paramname=" + encodeURIComponent(paramvalue), true);