Mozilla Firefox错误“JSON.parse:JSON数据的第1行第1列意外的数据结束”

问题描述 投票:0回答:2

当我试图从我的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"}

我该如何克服这个问题?

javascript php json
2个回答
1
投票

使用type: 'POST'。如果仍然无效,请尝试使用async: false


-1
投票

如上面的答案所说,我们可以改变XMLHttpRequet.open(中的async参数

sample.open(“GET”,url,false)。来自sample.open(“GET”,url,true)

我只在运行时才遇到这个bug,但是在调试时它很好。

© www.soinside.com 2019 - 2024. All rights reserved.