Before you try response.json, could you log the returned data on your console and give us an idea of what it looks like? It sounds like it's not a valid json.
Logging the response will help, but a quicker approach to debugging this would be to run it in the browser with dev tools open on the network tab and confirm that:
the request you're making is properly formed: e.g. string parameters are included as expected
the response is what you expect: i.e. json
You can see the contents by selecting the response in the list and it'll then show tabs where you can expand details
There's nothing wrong with console.log, but it soon becomes tedious adding and removing it from your code. That definitely takes longer than hitting
F12 + a couple of mouse clicks to get to the Network tab; which doesn't even require you to open your editor.
As others have said: the answer will be found by inspecting the response. It could be that you're actually receiving HTML - sometimes you see this when the request URL is blocked or you've passed invalid parameters...
Before you try
response.json, could you log the returned data on your console and give us an idea of what it looks like? It sounds like it's not a valid json.SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
But that's the error you're getting, isn't it? Try doing this:
And let us know what you get in the console after
Response:Logging the response will help, but a quicker approach to debugging this would be to run it in the browser with dev tools open on the network tab and confirm that:
You can see the contents by selecting the response in the list and it'll then show tabs where you can expand details
It's a different approach, I wouldn't say it's "quicker".
There's nothing wrong with console.log, but it soon becomes tedious adding and removing it from your code. That definitely takes longer than hitting
F12 + a couple of mouse clicks to get to the Network tab; which doesn't even require you to open your editor.
Maybe your
responseis empty.As others have said: the answer will be found by inspecting the response. It could be that you're actually receiving HTML - sometimes you see this when the request URL is blocked or you've passed invalid parameters...
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data