2013-05-09 25 views
1

這是Ajax調用我用得到來自其他服務的響應:休息Sercvices自定義狀態碼響應序列化

$.ajax({ 
    url: xxxxx, 
    cache: false, 
    dataType: 'json', 
    data: JSON.stringify(xxxx), 
    type: "POST", 
    contentType: 'application/json; charset=utf-8', 
    async: asyncType, 
    headers: { "ASP.NET_SessionId": apiReadCookie() }, 
    success: function (data, textStatus, jqXHR) { 
     callback(data, paramters); 
    }, 
    error: function (xhr, jqXHR, status, text) { 
     var response = JSON.parse(xhr.responseText); 
     console.log("The Current Response is " + jqXHR + " The Status is " + status + " The response is " + response); 
     if (response) { 
      console.log(response.error); 
     } else { 
     } 
    } 
}); 

輸出從我此行得到:

  console.log("The Current Response is " + jqXHR + " The Status is " + status + " The response is " + response); 

是:當前響應是錯誤狀態是內部服務器錯誤響應是[對象對象]

如何讀取響應對象?正如你所看到的,Json.parse不起作用,那麼還有其他的東西嗎?

&無論如何這是一個正確的方法還是有更好的?

+0

如果我的回答解決你的問題不要忘記給予好評,並標記爲最多的回答,讓其他人就會知道,如果他們面臨着同樣的問題 – 2013-05-09 13:09:24

回答

1
console.dir(<object>); 

將打印一個對象的內容到控制檯。

這樣:

console.log("Response is: "); 
console.dir(response); 

應該做的伎倆