所以基本上这是我的脚本,它是用index.php编写的-
<script type="text/javascript">
setInterval(function() {
jQuery.ajax({
url: "ajaxChecker.php",
context: document.body
}).done(function(response) {
if(response == true) {
location.reload(true);
}
});
}, 1000 * 60);
</script>它应该每分钟向balanceChecker.php发送接收数据的请求,然后检查它是否是真正的重新加载页面,否则什么都不做。
这是ajaxChecker.php文件
<?php
return true;
?>但它不起作用。有什么想法吗?
编辑了AJAX部分,现在也不能工作了-
setInterval(function() {
jQuery.ajax({
url: "ajaxChecker.php",
context: document.body,
success: function(response) {
if(response == "true") {
location.reload(true);
}
}
});
}, 1000 * 10); 并在ajaxChecker.php文件中替换了返回回显和true到"true“。
发布于 2012-07-06 21:43:32
你的php不会输出任何东西。
应该是:
<?php echo "true";?>在js中:
if(response == "true") {此外,我建议不要包含PHP结束标记:?>,以避免不必要的新行,并防止发送标题信息:
<?php
echo "true";发布于 2012-07-06 21:43:25
在你的php文件中写
<?php
echo true;//can also use echo 1
?>因为页面不能返回任何内容
发布于 2012-07-06 21:52:43
你可以用"success“代替.done:
var str="the data you want to send to ajaxChecker.php";
$.ajax({
type: "POST",
url: "ajaxChecker.php",
data: str,
success: function(msg) {
// msg is the return you receive from ajaxChecker.php
if(msg==1) {location.reload();}
}
}); https://stackoverflow.com/questions/11363364
复制相似问题