skip to Main Content

i am calling ajax and my success function says

success: function (data) {
        console.log(data.data);
},

And my response is

{"data":{"response":"{"ResCode":"TPB009","ResStatus":1}","http_code":200}}

i want to fetch ResCode so i tried this

console.log(data.data.response['ResStatus']);
        console.log(data.data.response['ResCode']);
        

but it is undefine any help?

2

Answers


  1. Your response seems to be in JSON format, use JSON parse

    success: function (data) {
       var jso = JSON.parse(data);
        ...
    },
    
    Login or Signup to reply.
  2. data.data.response is a JSON string, you need to parse it.

    let response = JSON.parse(data.data.response);
    console.log(response.ResStatus, response.ResCode);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search