K Rajitha
K Rajitha

Reputation: 316

Cannot Get status code from xhr response text

I have custom error messages returning from the server and i get it in the xhr.responseText.

{"timestamp":1544419441358,"status":900,"error":"Http Status 900","message":"Origin already exists","path":"/origin/add/"}

I need to get the status code from the above return response. I have tried following way

But i cannot get that error 900. What i am getting is undefined.

So how to get the status code from the response text.

Upvotes: 2

Views: 4650

Answers (1)

Mamun
Mamun

Reputation: 68933

I believe responseText is string, you have to parse the response first:

var responseText = JSON.parse(xhr.responseText);
var status = responseText.status;

Upvotes: 4

Related Questions