Skip to content
Advertisement

Get Reponse Code and JSON Response in Fetch

I have following Code to get the Response from the API. Now I want a response if the data are successfully send to the server. My first idea was to do it with the response code. If it is 200 it is successfull. The other idea is, to make it with a try catch statement.

JavaScript

Getting the response from the server it was successful.

Advertisement

Answer

Looking at the response properties you can simply check response.ok. Something like this:

JavaScript
Advertisement