我正在使用返回JSON數據的Web服務。JSON未加載jQuery.ajax()
test.com/incident.do?JSON & sysparm_action = getRecords
加載此網址在瀏覽器提示我打開incident.do,這在記事本中打開顯示有效JSON數據。
然後,在同一個域中的網頁,我用這個:
$.ajax({
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', authinfo);
},
url: "https://test.com/incident.do?JSON&sysparm_action=getRecords",
dataType: 'json',
type: 'GET',
success: function(a,b,c) {
alert(a);
}
});
然而,與此代碼我沒有收到任何JSON,我只得到這個響應
HTTP/1.1 200 OK
Date: Tue, 13 Jul 2010 22:28:09 GMT
Server: Apache-Coyote/1.1
Allow: GET, HEAD, POST, TRACE, OPTIONS
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/plain
我在這裏做錯了什麼?
編輯:如果它可以幫助任何人,我對供應商的網站鏈接到沙箱提供相同的功能...該用戶名/密碼是admin /管理員
https://demo.service-now.com/incident.do?JSON&sysparm_action=getRecords
是該網址的Content-Type'application/json'嗎? – 2010-07-13 22:32:17
@meder 是的我試過設置Content-Type,同樣的問題。 – imagineblue 2010-07-13 22:34:31
如果你沒有收到來自web服務的Content-Type:application/json'迴應,那麼即使它回覆了一個json對象也是行不通的。 – Rodrigo 2010-07-13 22:35:06