$.getJSON - ajax 已发送,但回调函数被忽略 - Internet Explorer
所以这是我的函数
function ajax(addr,loading, loadTo, json){
addr = addr.replace(' ', '');
if (loading){
$("#"+loading).fadeIn();
}
if (json){
$.getJSON(addr, function(data){
alert('whoooo working'); // <--- it never goes here
if (loading){
$("#"+loading).fadeOut();
}
procJSON(data);
});
return true;
}
}
,我用
var postid = $(this).attr('data-postid');
ajax(url+'tools/delete/'+postid, 'loading'+postid, false, true);
ajax 发送调用它,显示图像(加载图像),但从未调用回调函数。
这不就是 IE 大列表中的新保留值吗?是的,我知道,IE 不是有效的浏览器,但我不能责怪我的客户
So here is my function
function ajax(addr,loading, loadTo, json){
addr = addr.replace(' ', '');
if (loading){
$("#"+loading).fadeIn();
}
if (json){
$.getJSON(addr, function(data){
alert('whoooo working'); // <--- it never goes here
if (loading){
$("#"+loading).fadeOut();
}
procJSON(data);
});
return true;
}
}
and I'm calling it with
var postid = $(this).attr('data-postid');
ajax(url+'tools/delete/'+postid, 'loading'+postid, false, true);
ajax is sent, image (loading image) is showed, but callback function is never called.
Isn't that just new reserved value from that IE's big list? Yes I know, IE is not a valid browser, but I can't blame my customers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于它在特定浏览器中失败,因此很可能是响应中意外标头的组合,以及浏览器如何基于该标头处理数据。
例如,如果响应的内容类型为
text/html
而不是application/json
,则浏览器可能会尝试将响应内容转换为 HTML 文档(通过添加>pre
标签),这会导致 JSON 解析失败。如果您使用
$.ajax
方法,您还可以捕获任何错误消息,这将为您提供有关发生情况的线索:As it fails in specific browsers, it's likely that it is a combination of unexpected headers in the response, and how the browser handles the data based on that.
If for example the response has the content type
text/html
instead ofapplication/json
, the browser might try to turn the response content into a HTML document (by addingpre
tags around it), which would then cause the JSON parsing to fail.If you use the
$.ajax
method, you can also catch any error message, which would give you a clue to what's going on: