JQuery JSON Calls To PHP WebService Always Runs “Error” Callback

后端 未结 4 1082
清酒与你
清酒与你 2020-12-11 11:38

I\'m having this headache now, since I\'ve been having this problem the whole day and, still, can\'t fix it. I\'ve looked on Google and StackOverflow for hours, tried many m

相关标签:
4条回答
  • 2020-12-11 11:42

    Just change your response to text and then parse the text as JSON, example:

    var json = JSON.parse(data);

    0 讨论(0)
  • 2020-12-11 11:48

    because you are doing cross domain calls you need to use JSONP. The PHP server must form a response that looks like this: callback( jsonSyntax);

    0 讨论(0)
  • 2020-12-11 11:51

    Try to change the JQuery URL from :

    http://www.example.com/ws/webservice.php/methodName
    

    To:

    http://www.example.com/ws/webservice.php?method=methodName
    

    And then try to read it from the $_GET['method'] from PHP, I think this should be your problem

    0 讨论(0)
  • 2020-12-11 12:05

    Change

    contentType: "application/json utf-8",
    

    to

    contentType: "application/json; charset=utf-8",
    

    The malformation of your contentType header is causing your server to incorrectly interpret the content of your POST request.

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