...

View Full Version : Parse POST results token



justind000
09-25-2010, 06:57 PM
I'm making a javascript POST that returns some information in this format. It's copied from the web API website I'm developing from.

Returns a token on success.


{
"errors": [
],
"warnings": [
],
"data": {
"token": "ta98585435afabcf26319e2038a09f40"
},
"page": {
"current": 1,
"total": 1
}
}

How can I get the data.token bit out specifically?

Dormilich
09-25-2010, 10:35 PM
er, data.token?

justind000
09-26-2010, 05:37 AM
The result comes back as an array of information. There is an element called data.token.

martin_narg
09-26-2010, 07:22 PM
When you make your call to the server to get the JavaScript, it comes back as a string and requires converting to JavaScript code using eval()

It's a good idea to error handle it:



try {
var json = eval(YourServerResponseJavaScript);
} catch(e) {
alert('Invalid JS from server');
return;
}


var theToken = json.data.token;



Hope this helps

m_n



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum