Php Can';我无法让这个AJAX请求正常工作
基本上这是我的脚本,在index.php中-Php Can';我无法让这个AJAX请求正常工作,php,jquery,html,ajax,Php,Jquery,Html,Ajax,基本上这是我的脚本,在index.php中- <script type="text/javascript"> setInterval(function() { jQuery.ajax({ url: "ajaxChecker.php", context: document.body }).done(function(response) { if(response =
<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>
在ajaxChecker.php文件中,将return to echo和true替换为“true”。在php文件中写入
<?php
echo true;//can also use echo 1
?>
因为页面不能返回任何内容,所以php不会输出任何内容 应该是:
<?php echo "true";?>
另外,我建议不要包含PHP结束标记:?>
,以避免不必要的新行,并防止发送标题信息:
<?php
echo "true";
您可以使用“成功”代替。完成:
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();}
}
});
输出1
,因为这就是true
的作用。好的,谢谢!现在我更进一步,它向我发送了一个错误-uncaughttypeerror:Object#没有“完成”方法,因为您应该使用的jQuery ajax方法是success
好的!谢谢,我要试一试!使用success
而不是.done
,请参见下面我的答案…不,很抱歉,您甚至没有在ajaxChecker.php中获得传递的数据。。。如Random建议的,echo 1怎么样?您尝试过不使用setInvervall吗?只是ajax部分本身?…啊,如果您使用$,可能会有所帮助。ajax({
,以前没有见过jQuery.ajax
)。。。
if(response == "true") {
<?php
echo "true";
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();}
}
});