我正在使用AJAX
請求到submit
a form
登錄。Parserror在AJAX請求中,表單提交
$.post(url, {data: JSON.stringify({obj: value})}, 'json')
.fail(function(){
console.log(typeof arguments[0].responseText) //logs 'string'
//console.log(JSON.parse(arguments[0].responseText)) // decommented logs "unexpected token"
console.log(arguments)
});
我越來越
1: "parsererror"
2: SyntaxError
message: "Unexpected token "
..
..
我還設置header("Content-type: application/json")
但它並沒有解決這個問題, 我還使用json_encode
作爲服務器端的響應。
我得到status: 200
,看起來好像是json
responseText
。我不知道還有什麼要做。
(不要將此問題作爲一個重複的,我這樣做搜索過,沒有問題解決了我的問題)
編輯 新增responseText
鉻
responseText: "↵{"success":true,"error":false}"
firefox
"\r\n{"success":true,"error":false}"
EDIT2
json_encode(array(..))
介紹\r\n
,但我不知道爲什麼。
的URL返回什麼?只是'串'?那麼它不是一個有效的JSON – SajithNair
你可以添加'responseText'或螢火蟲屏幕截圖嗎? – Girish
用回覆文本編輯了問題 – steo