LoginSignup
1
1

More than 3 years have passed since last update.

Uncaught SyntaxError: Unexpected token < in JSON at position 0というエラーの解決方法

Posted at

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(値);

と返してあげれば上手くいきました。

以上です。(´ω`)ノ

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1