热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

400错误时无法获得responseText-impossibletogettheresponseTextwhen400error

Imworkingontheconnectionbetweenafront-webandarestservice.Isucceededtomakeacross-do

I'm working on the connection between a front-web and a rest service. I succeeded to make a cross-domain Ajax call but i'm still having a little problem.

我正在研究前端网络和休息服务之间的连接。我成功地进行了跨域Ajax调用,但我仍然遇到了一些问题。

Impossible to receive the responseText when occure a 400 error.

发生400错误时无法接收responseText。

I verified with wireshark, and i'm sure the responseText was send by the REST. But when i look in firebug i've this :

我用wireshark验证了,我确定responseText是由REST发送的。但是,当我看到萤火虫时我就是这样的:

POST http: api.yutagz.com users 400 Bad Request 133ms

POST http:api.yutagz.com用户400 Bad Request 133ms

Object { readyState=0, status=0, statusText="error" respOnseText= ""}

对象{readyState = 0,status = 0,statusText =“error”respOnseText=“”}

The '400 Bad Request' is ok, but i need the responseText to say the user what really happen.

'400错误请求'没问题,但我需要responseText来告诉用户实际发生了什么。

Here is my call code (working on success event) :

这是我的呼叫代码(处理成功事件):

$.ajax({
type: "POST",
url : "http://api.yutagz.com/users",
data: dataString,
dataType: 'json',
success : function(data,data1,data2){
    alert("OK : "+data);
    console.log(data2);
},
error:function (xhr){
    alert(JSON.stringify(xhr));
    console.log(xhr);
    switch (xhr.status) {
        case 404: alert("404");
        case 400: alert("400");
             // Take action, referencing xhr.responseText as needed.
    }
},
complete :  function (xhr){
    alert(JSON.stringify(xhr));
    console.log(xhr);
    switch (xhr.status) {
        case 404: alert("404");
        case 400: alert("400");
             // Take action, referencing xhr.responseText as needed.
    }
}
}); 

Here is a test (working with Chrome but not with firefox 3.6):

这是一个测试(使用Chrome但不使用firefox 3.6):

http://jsfiddle.net/RTvQQ/

http://jsfiddle.net/RTvQQ/

And here a jQuery ticket:

这里有一个jQuery票:

http://bugs.jquery.com/ticket/7868

http://bugs.jquery.com/ticket/7868

1 个解决方案

#1


1  

I see in Chrome 13:

我在Chrome 13中看到:

And in FF6:

在FF6中:

So just use error.message and go from there.

所以只需使用error.message并从那里开始。


推荐阅读
author-avatar
手机用户2602920567
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有