WCF JSONP jQuery 未传递正确的状态
我的问题非常简单。我希望在调用 WCF 服务时通过 JSONP 结果将正确的状态代码传递到我的成功或错误方法。
当 WCF 处理 jsonp 响应且状态代码不是 200 时,它会将状态代码作为回调方法中的第二个参数发送。这对我来说似乎合乎逻辑,但我无法在任何地方找到 JSONP 规范来查看其是否符合规范。
返回内容为:jQuery123456(null, 401); 然后 jQuery 将此视为成功,调用我的成功方法,但 401 却找不到。我通过执行 console.dir(arguments); 来确保这一点
我现在要做的是覆盖回调方法名称并自己处理所有这些,但我不想这样做。
jQuery 需要支持类似的东西。
更新:您不能重写该方法,因为 jQuery 会认为存在错误并弹出错误消息。
My issue is very straight forward. I want the correct status code passed through to my success or error methods through a JSONP result when its calling a WCF service.
When WCF is handling a jsonp response, and the status code is not 200, it sends the status code as the 2nd parameter in the callback method. This seems logical to me, but I cannot find JSONP specs anywhere to see if its correct to specs.
The returned content is: jQuery123456(null, 401);
jQuery then treats this as a success, calls my success method, but the 401 is no where to be found. I made sure of this by doing a console.dir(arguments);
What I'm going to be doing now, is overriding the callback method name and handle all that myself, but I'd rather not have to do that.
Something like this needs to be supported in jQuery.
Update: You cannot override the method because then jQuery thinks there was an error and pops up an error message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑这是因为 JQuery 无法知道请求的状态,因为它是通过脚本标记完成的,而不是 XHR 对象。如果您深入研究 JQuery,“200”将被传递到 did() 回调中。
I suspect this is because JQuery can't know the status of the request because it is done via a script tag, not an XHR object. '200' is passed into the done() callback if you look into the depths of JQuery.
您知道吗,您无法使用 JSONP 方法访问状态代码,您可以阅读 Angularjs 开发人员的这个答案,它非常清楚:
https://github.com/angular/angular.js/issues/1423 #issuecomment-10768224
托马斯
Do you know you can't access to the status code with the JSONP method, you can read this answer from an Angularjs developer it's pretty clear :
https://github.com/angular/angular.js/issues/1423#issuecomment-10768224
Thomas