我有一些jQuery的是成功地擊中了終點,這裏是我的代碼未捕獲的SyntaxError:意外的令牌:返回JSON
$.ajax({
dataType: "json",
type: "GET",
url: "https://url.that-works.com/env/Development/GetDevs/",
username: "username",
password: "password",
data: "callback=?"
})
.done(function (data) {
alert("success");
})
;
的代碼返回以下JSON響應 - 我可以在Chrome中看到開發工具:
{
"developments": [
{
"name": "h2010 Ph2"
},
{
"name": "The Meadows Ph2"
},
{
"name": "h2010 Ph3"
},
{
"name": "h2010 Ph4"
},
{
"name": "The Meadows Ph3"
}
]
}
我檢查,這是返回有效的JSON,但我不斷收到錯誤消息:未捕獲的SyntaxError:意外的標記:
我不確定我在這裏做錯了什麼,或者爲什麼我收到這條消息,任何指導都會非常感激。
bengrah。
你從哪裏得到這個錯誤? – epascarello
沒有返回application/json作爲MIME類型?? – vogomatix
@vogomatix - 不可以。 'dataType:「json」,'導致jQuery忽略內容類型 – Quentin