JQuery getJSON - ajax parseerror

后端 未结 17 1812
南笙
南笙 2020-12-01 13:04

I\'ve tried to parse the following json response with both the JQuery getJSON and ajax:

[{\"iId\":\"1\",\"heading\":\"Management Services\",\"body\":\"

相关标签:
17条回答
  • 2020-12-01 13:27

    It is maybe because your output buffer is not empty, so AJAX receive bytes which don't belong to the JSON.

    Try clean buffer with ob_clean() on server side just before output your json with echo or die(). And you don't need to specify contentType, I think for you default value will work correctly.

    I had the same problem and it solve it.

    Hope to help you.

    0 讨论(0)
  • 2020-12-01 13:28

    in my case, the error was caused by a html tag in the json.

    INCORRECT (parsererror)

    {"msg": "Gracias,< br >Nos pondremos en contacto."}
    

    CORRECT

    {"msg": "Gracias, nos pondremos en contacto."}
    

    BROWSER: IE7/IE8

    0 讨论(0)
  • 2020-12-01 13:30

    The value you are trying to parse is wrapped in brackets [], which means it is an array. You are trying to eval an array. Try to eval the first element of the array, and it should work...

    var json = eval("("+data[0]+");");
    

    Also, I would recommend using the JSON.parse() provided here instead of calling eval() directly.

    0 讨论(0)
  • 2020-12-01 13:30

    also try this

    $.ajax({
        url: url,
        data:datas,
        success:function(datas, textStatus, jqXHR){
        var returnedData = jQuery.parseJSON(datas.substr(datas.indexOf('{')));
    })};
    

    in my case server responds with unknow character before '{'

    0 讨论(0)
  • 2020-12-01 13:30

    Don't use an array box, and make sure you format your data properly:

    {"account":{"iId":"1","heading":"Management Services","body":"<h1>Program Overview</h1><h1>January 29, 2009</h1>"}}
    
    0 讨论(0)
  • 2020-12-01 13:35

    Disabling Firebug Lite fixed this problem for me.

    Bug with combination of: jQuery 1.4, ajax/json, Firebug Lite and IE 8

    0 讨论(0)
提交回复
热议问题