我想用ajax,我曾经使用过它,复制我以前的HTML文件中的代码,并改变了价值观发送,PHP文件来处理的代码和我” m使用POST方法。但是,php脚本不会返回任何内容到html页面。我已经检查了所有可以,所以我现在在这里。 var x = document.getElementsByTagName('option')[document.getElementById(“region”)。selectedIndex] .value; var ajaxRequest; //使Ajax成为可能的变量!PHP的任何结果,不返回到JavaScript的Ajax对象
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data
// sent from the server and will update
// modal section in the same page.
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById("accordion");
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
// Now get the value from user and pass it to
// server script.
ajaxRequest.open("POST", "search.php", true);
ajaxRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
alert(x);
ajaxRequest.send("region=" + x);
}
PHP代码是一个简单的
<?php
echo "The world is blue.";
?>
的是,它没有返回到所选择的股利。
首先,我建议使用像jQuery这样的框架,它使AJAX变得更容易。其次,你确定你从PHP获得结果吗? – cgf
这就是问题所在,我没有从php获得任何结果。我有另一个适用于此的应用程序,但是,这个应用程序不会将任何内容返回给id为“accordion”的div。 – Michael
@Michael你的PHP是原始的,必须工作。尝试使用您的JavaScript代码的萤火虫。 – user4035