当我试图从我的API获得响应时,我得到JSON.parse:在JSON数据的第1行第1列意外结束数据此错误在Mozilla Firefox浏览器中而不是在Chrome浏览器中。
$.ajax({
dataType: 'json',
url: myApiUrl,
data: data,
type: 'post',
success: function(result)
{ alert("success");}
});
注意:假设myApiUrl变量包含我的url,数据包含我的参数。
以下是我的Json回应
{"type":"Sale","status":1,"transaction_id":"T4U_122a668896_4bdadcc57","ErrorMSG":"Success","ErrorCode":"00","passive_data":"####aaaa","total":"10.47","time":"31-01-2017 09:56:55"}
我该如何克服这个问题?
使用type: 'POST'
。如果仍然无效,请尝试使用async: false
如上面的答案所说,我们可以改变XMLHttpRequet.open(
中的async参数
sample.open(“GET”,url,false)。来自sample.open(“GET”,url,true)
我只在运行时才遇到这个bug,但是在调试时它很好。