[英]ajax: no data from local server
I'm using php on a linux machine. 我在Linux机器上使用php。 My html code issues an ajax request to the local apache server ( http://localhost ), and the data from the server should be printed out on the screen.
我的html代码向本地apache服务器( http:// localhost )发出ajax请求,并且来自服务器的数据应在屏幕上打印出来。 However, nothing gets printed.
但是,什么都不会打印。
The code on the "client" side (the html file which I load in the browser) is: “客户端”端的代码(我在浏览器中加载的html文件)为:
<html>
<body>
<script language="javascript" type="text/javascript">
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
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;
}
}
}
ajaxRequest.onreadystatechange = function(){
if( ajaxRequest.readyState == 4 ){
document.writeln( ajaxRequest.responseText );
}
}
ajaxRequest.open("GET", "http://localhost/s.php", true);
ajaxRequest.send(null);
}
</script>
</body>
</html>
and the "server" script (which is /var/www/s.php) is: 并且“服务器”脚本(/var/www/s.php)为:
<html>
<body>
<?php
echo date("H:i:s");
?>
</body>
</html>
Any suggestions? 有什么建议么?
TIA TIA
You should debug your code 您应该调试代码
alert(ajaxRequest.readyState);
alert(ajaxRequest.readyState);
alert(ajaxRequest.responseText);
alert(ajaxRequest.responseText);
页面加载时似乎没有任何调用ajaxFunction
的内容,因此从不发送请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.