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

后端 未结 2 1774
傲寒
傲寒 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.

    PHP warning: blah blah blah

    {"foo":"bar"}

    The leading < in the

    ... 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.

提交回复
热议问题