[英]jQuery $.getJSON http request fails, while making the exact same request manually works
Ok, I'm really stuck here. 好吧,我真的被困在这里。
This is my little test file that I'm using to test a little script I wrote: 这是我的小测试文件,用于测试编写的小脚本:
<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
$.getJSON(
"/php/banners/check_advertorial.php",
{ ID : 78 },
function(data) {
console.log("callback");
console.log(data);
if(data)
alert("yay");
else
alert("nay");
}
);
</script>
This is what check_advertorial.php looks like, I simplified it for testing purposes. 这就是check_advertorial.php的样子,出于测试目的,我对其进行了简化。
<?php
header('Content-Type: application/json');
echo json_encode(true);
?>
So I monitor the requests in Chrome, and the call to check_advertorial fails, no response. 因此,我在Chrome中监控了请求,对check_advertorial的调用失败,没有响应。 Not even an error code. 甚至没有错误代码。 But if I copy the request URL, and just paste it into the browser, I get a successful request and it prints "true". 但是,如果我复制请求URL,然后将其粘贴到浏览器中,则会收到成功的请求,并显示“ true”。
What gives? 是什么赋予了?
UPDATE: I have tested it in different browsers. 更新:我已经在不同的浏览器中对其进行了测试。
UPDATE 2: As Hüseyin BABAL pointed out, ABP blocked the request because it had the word "advertorial" in it. 更新2:正如HüseyinBABAL指出的那样,ABP阻止了该请求,因为其中包含“广告”一词。
Add status check code to your query in order to detect your request fails or not; 将状态检查代码添加到查询中,以检测您的请求是否失败;
var jqxhr = $.getJSON( "/php/banners/check_advertorial.php", {ID:78}, function(data) {
})
.done(function() {
console.log("callback");
console.log(data);
if(data)
alert("yay");
else
alert("nay");
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
console.log( "error occured: " + err );
});
Edit: Also be sure that you are not using adblock plugin 编辑:还请确保您没有使用adblock插件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.