JSON.parse: unexpected character

后端 未结 2 1299
礼貌的吻别
礼貌的吻别 2020-12-11 22:00

I\'m trying to pass a json from php jquery, after getting into an array of sql query and get the following javascript error.

JSON.parse: unexpected character         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 22:34

    You don't need the $.parseJSON call as jQuery automatically does it because if you don't specify a dataType property jQuery tries to guess it and calls the correct function to parse the response before the data is handled to the success function

       $.ajax({
            type: 'POST',
            url:$(this).attr('action'),
            data:$(this).serialize(),
            success:function(data)
            {
              //console.log("SUCCESS " + data);
              var json_cli = data;
            }
        })
    

    check out also this question Why is 'jQuery.parseJSON' not necessary?

提交回复
热议问题