2011-09-15 5 views
7

私はフロントウェブとレストサービスの間の接続に取り組んでいます。 クロスドメインのAjaxコールに成功しましたが、まだ少し問題があります。400エラー時にresponseTextを取得することができません

400エラーが発生した場合、responseTextを受け取ることはできません。

私はwiresharkで確認しましたが、私はresponseTextがRESTによって送信されたと確信しています。

POSTます。http:api.yutagz.comユーザー400の不正な要求133ms

オブジェクト{readyStateの= 0、ステータス= 0、STATUSTEXT = "エラー" responseText私は放火犯で見たときに私はこれをしました= ""}

「400 Bad Request」は問題ありませんが、本当に何が起こったのかをユーザーに伝えるためにresponseTextが必要です。ここで

は私の呼び出しコード(成功イベントに取り組んで)です:

http://jsfiddle.net/RTvQQ/

そしてここに:ここで

$.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. 
    } 
} 
}); 

はテスト(Firefoxの3.6とChromeでの作業ではない)でありますjQueryチケット:

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

+0

Chromeでは、これは問題なく機能しています。 "{" error ":{" type ":" badRequest "、" message ":" errorUserEmailMissing "}}" " –

+0

Firefox 5で動作しています。しかし、3.6で何が起こっているのですか? –

答えて

1

私はクローム13で参照してください。

そしてFF6で:

だからerror.messageを使用して、そこから行きます。

関連する問題