Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
98
rated 0 times [  100] [ 2]  / answers: 1 / hits: 22210  / 14 Years ago, fri, march 18, 2011, 12:00:00

I'm trying to develop a web application using jQuery, AJAX and JSON.
I have this code:



console.log(response.s);
if (response.s == true) {
alert('good');
} else {
alert('bad');
}


This response (via console.log() on Firebug) seems to be:



{s:true}


Which seems to be a JSON object right?
Well, the line console.log(response.s); on the first code I added here returns undefined. What's the problem?


More From » jquery

 Answers
19

What is typeof (response)? if it's a string then you have to parse it, first. (You'd be accessing the s field of a string, which doesn't exist, so JavaScript gives you undefined instead of throwing an Exception or whatever.)


[#93205] Thursday, March 17, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
denism

Total Points: 627
Total Questions: 96
Total Answers: 98

Location: Ivory Coast
Member since Sun, Mar 7, 2021
3 Years ago
;