当我尝试从我的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(
中更改异步参数 )
sample.open("GET", url, false). from sample.open("GET", url, true)
我只在运行时遇到了这个错误,但在调试时它很好。