Reading JSON Ajax response?
I have an ajax response from my server. Example below:
{"user_id":"93","status_message":"Cool Status","timestamp":"1305648702"}
I tried reading the response using:
var json = eval(response);
var userid = json.user_id;
The above does not s开发者_开发技巧eem to work though. Any ideas.
You should use the JSON parser that is built in to many browsers these days. If it's not available, you can use the JSON2 library, which provides the same interface, as a fallback.
var json = JSON.parse(response);
var userid = json.user_id;
Try it without the eval(response)
and just do:
var userid = response.user_id;
I think you want to do
var json = JSON.parse(response);
var userid = json.user_id;
精彩评论