最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Mozilla Firefox error "JSON.parse: unexpected end of data at line 1 column 1 of the JSON data" -

programmeradmin2浏览0评论

When I am trying to get response from my API I am getting JSON.parse: unexpected end of data at line 1 column 1 of the JSON data this error in Mozilla Firefox Browser but not in Chrome browser.

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

Note : assume that myApiUrl variable contains my url and data contains my parameters.

Following is my Json Response

{"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"}

How should I overe that problem?

When I am trying to get response from my API I am getting JSON.parse: unexpected end of data at line 1 column 1 of the JSON data this error in Mozilla Firefox Browser but not in Chrome browser.

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

Note : assume that myApiUrl variable contains my url and data contains my parameters.

Following is my Json Response

{"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"}

How should I overe that problem?

Share Improve this question edited Jan 31, 2017 at 8:23 Nitesh Kuyate asked Jan 30, 2017 at 14:25 Nitesh KuyateNitesh Kuyate 1652 gold badges2 silver badges13 bronze badges 5
  • Can you post the JSON as well? – evolutionxbox Commented Jan 30, 2017 at 14:27
  • can you add a snippet of your data object? – Noushad Commented Jan 30, 2017 at 14:27
  • var data= { total:grandtotal, customer_firstname:firstname, customer_lastname:lastname, customer_email:email, customer_phone:phone, bank_id:bank_id, gateway:gateway} – Nitesh Kuyate Commented Jan 30, 2017 at 14:31
  • Is "var data=" also part of the response? I can not believe that the JSON response you have written in your post (not in your ment but in your post) is the actual output Firefox is giving you. What is the EXACT return value Firefox gives back to you in the success callback? – John Smith Commented Jan 31, 2017 at 9:19
  • @John Smith "var data=" is not part of response. Actual response was null but im getting null in ajax. – Nitesh Kuyate Commented Jan 31, 2017 at 11:16
Add a ment  | 

2 Answers 2

Reset to default 1

Use type: 'POST'. If it still doesn't work, try using async: false

Like the above answer says, we can change async parameter in XMLHttpRequet.open() like

sample.open("GET", url, false). from sample.open("GET", url, true)

I met this bug only when running, but when debugging it is good.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论