Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
121
rated 0 times [  123] [ 2]  / answers: 1 / hits: 31590  / 12 Years ago, fri, july 27, 2012, 12:00:00

I have a problem with my jquery ajax. I have this code:



$.ajax({
url: '/users/validatepassword/'+current,
success: function(data){
status = data;
},
async: false
});

if(status == Password correct)
{
//do something
}


Basically, I want to capture the data that was returned on success. But I cannot make a way for the if statement to work. I am think the data was not a string so I cannot make a comparison.


More From » jquery

 Answers
28

Define status outside ajax call. then access that everywhere.



var status = '';
$.ajax({
url: '/users/validatepassword/'+current,
async: false,
dataType: json,
success: function(data){
status = data;
},

});

if(status == Password correct)
{
//do something
}


At users/validatepassword use json_encode()



echo json_encode(Password correct);

[#84027] Wednesday, July 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
victorw

Total Points: 484
Total Questions: 120
Total Answers: 107

Location: Faroe Islands
Member since Thu, Apr 8, 2021
3 Years ago
;