简体   繁体   中英

Pulling JSON body from API Response using Javascript

I'm using a parse.com API server which I am successfully communicating with in Javascript using AJAX.

I am writing output from the return into the browser console as follows:

    $.ajax(settings).done(function(response) {
                            console.log(response);
                        })
                        .fail(function(response){
                        console.log("Fail Return is: " + response);
                        });

Within this response is a JSON body containing a message such as follows:

{
  "code": 202,
  "error": "Account already exists for this username."
}

How would I extract this from the response into say a separate console message?

OK,

After getting help externally, this does the job:

console.log("Fail Return is: " + temp.error);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM