【问题标题】:Mozilla Firefox error "JSON.parse: unexpected end of data at line 1 column 1 of the JSON data"Mozilla Firefox 错误“JSON.parse:JSON 数据的第 1 行第 1 列的数据意外结束”
【发布时间】:2017-01-30 14:25:41
【问题描述】:

当我尝试从我的 API 获得响应时,我收到 JSON.parse: unexpected end of data at line 1 column 1 of the JSON data Mozilla Firefox 中的此错误 strong> 浏览器,但不在 Chrome 浏览器中。

            $.ajax({
                    dataType: 'json',
                    url: myApiUrl,
                    data: data,
                    type: 'post',
                    success: function(result)
                    { alert("success");}
                  });

注意:假设 myApiUrl 变量包含我的网址和 data 包含我的参数。

以下是我的 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"}

我应该如何克服这个问题?

【问题讨论】:

  • 你也可以发布 JSON 吗?
  • 您可以添加数据对象的 sn-p 吗?
  • var data= { total:grandtotal, customer_firstname:firstname, customer_lastname:lastname, customer_email:email, customer_phone:phone, bank_id:bank_id, gateway:gateway}
  • “var data=" 也是响应的一部分吗?我无法相信您在帖子中(不是在您的评论中而是在您的帖子中)写的 JSON 响应是 Firefox 给您的实际输出。 Firefox 在成功回调中返回给您的确切返回值是多少?
  • @John Smith "var data=" 不是响应的一部分。实际响应为空,但我在 ajax 中得到 null

标签: javascript php json


【解决方案1】:

使用type: 'POST'。如果还是不行,试试async: false

【讨论】:

  • type: 'POST' used already and when Im using async: false 给出 null 作为响应。
【解决方案2】:

就像上面的答案所说,我们可以改变XMLHttpRequet.open() 中的异步参数,比如

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

我是在运行的时候才遇到这个bug,但是调试的时候就好了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-15
    • 2021-03-22
    • 2016-01-30
    • 2020-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多