SyntaxError: Unexpected token < in JSON at position 0 at Object.parse (native) (AngularJS)

后端 未结 2 1770
傲寒
傲寒 2021-01-02 23:57

I\'m successfully saving my data into a json file with a php script (save-data.php) but I\'m unable to fetch it correctly with my get-data.php script.

Er

相关标签:
2条回答
  • 2021-01-03 00:38

    Invariably, 99.9999999% of the time you get Unexpected token < in JSON as position 0 in the error, you did NOT receive json from the server. You received an HTML error message with your json following afterwards.

    <p>PHP warning: blah blah blah</p>
    {"foo":"bar"}
    

    The leading < in the <p>... is where the error comes from, because that's position 0 (first character).

    Check the raw data coming back from the server, and fix whatever the error/warning that PHP is spitting out.

    0 讨论(0)
  • 2021-01-03 00:42

    Please Check your PHP file. In that might be unwanted echo is present so the json response could not get the exact response. I resolve my issue in this way. Hope this is helpful!!

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