Laravelでアプリを開発しており、JavaScriptのAjax
を使っていると下記のようなエラーに遭遇しました。
Uncaught SyntaxError: Unexpected token < in JSON at position 0
3~4時間ぐらいずっとエラーで悩んでいたけど、こちらの記事( https://stackoverflow.com/questions/53771865/error-uncaught-syntaxerror-unexpected-token-in-json-at-position-0 )の
In my experience, Ajax calls returning HTML is a sign that there has been an error in the back end. If you use your browser's developer tools, you'll be able to track your Ajax call and read its response.
という文章が参考になり解決しました。
結論を言うと『コントローラーからjsonを返していなかったから』です。
return response()->json(値);
と返してあげれば上手くいきました。
以上です。(´ω`)ノ