jquery ajax 200 OK JSON.ParseError

前端 未结 3 608
别那么骄傲
别那么骄傲 2020-12-20 22:13

I have a control which has a textbox which, when its content changes, will tricker this javascript function:

page parameter is document.URL

相关标签:
3条回答
  • 2020-12-20 22:48

    Not sure about [WebMethod], but it seems that the problem is there, and it is related with the output of that method. It has to be a well formed JSON for the ajax method to work. So what I would do is to check call that in a separate window to see the respons and to use something like http://jsonlint.com/ to make sure it is well formed.

    0 讨论(0)
  • 2020-12-20 23:09

    Had the same problem with AJAX's 'post' command.

    Sent a JSON post request, got a 200 OK repsponse but textStatus was parseerror and errorThrown was SyntaxError: JSON.parse: unexpected character.

    This is my JS code:

    $.post(url, JSON.stringify(reportVarsJson), function(response) {}, 'json')
    .fail(function(jqXHR, textStatus, errorThrown) {
        alert('Error saving report request variables:\n\n' + jqXHR.responseText);
    });
    

    The problem turned out to be that my server view (Django) returned an empty response which was not a JSON response.

    I changed my server view to return an empty json response and everything works well!

    0 讨论(0)
  • 2020-12-20 23:11

    Try to remove contentType and dataType from Ajax parameters and let them be identified automatically

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