jQuery的阿贾克斯错误回调不触发 [英] jQuery ajax error callback not firing

查看:104
本文介绍了jQuery的阿贾克斯错误回调不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我请求的URL与阿贾克斯,结果在一个HTTP头code 500。我希望它可以触发错误的功能:

I am requesting a URL with ajax that results in a HTTP header code 500. I would expect this to trigger the error function:

    $.ajax({
  url: "http://xxx",
  dataType: "jsonp",
  crossDomain: true,
  success: function( data ) {
        alert('success');
  },
  error: function () {
        alert('error');
  }
});

这工作在Safari浏览器,但无法在Chrome和Firefox。

This works in safari, but fails in chrome and firefox.

我是什么做错了吗?

这是最新的jQuery 1.4.X,至于原因,我不能升级到更高版本。

This is the latest jquery 1.4.X, for reasons I cannot upgrade to later versions..

响应发送一个HTTP code 500,内容类型application / JSON和内容:

The response sends a HTTP code 500, content type application/json and contents:

jsonp1310063232212({错误:{理由:用户未找到}})

jsonp1310063232212({"error":{"reason":"User not found"}})

推荐答案

看起来跨域:未添加到jQuery的1.5

It looks like crossDomain: wasn't added until jQuery 1.5.

http://api.jquery.com/jQuery.ajax/

跨域(增加1.5)

默认值:false   对于同一个域名的请求,适用于   跨域请求。

Default: false for same-domain requests, true for cross-domain requests.

如果您希望   强制跨域请求(如   JSONP)在同一个域中,设置   跨域的值设置为true。本   允许,例如,服务器端   重定向到另一个域

If you wish to force a crossDomain request (such as JSONP) on the same domain, set the value of crossDomain to true. This allows, for example, server-side redirection to another domain

像马丁Larente暗示,它可能是一个问题,如何不同的浏览器或jQuery的检测/报告JSONP错误。

Like Martin Larente suggested in his comment, it could be an issue with how different browsers or jQuery detects/reports JSONP errors.

这篇关于jQuery的阿贾克斯错误回调不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆