Assigning jQuery ajax response text to variable constanty returns null
Posted
by
Dan Twining
on Stack Overflow
See other posts from Stack Overflow
or by Dan Twining
Published on 2011-01-10T00:43:25Z
Indexed on
2011/01/10
0:53 UTC
Read the original article
Hit count: 144
Hi all, hopefully one of you on this great site can help. I'm having issues with assigning a variable to a jQuery ajax call response text.
I have a form which when submited runs my "checkemail" function to varify the email address can be found in a database. If it's found, the responseText == "true", else "false". This works fine, and can be seen ok using Firebug....but the actual variable the response text should be assigned to is constantly showing "", and therefore causing the function to return false all the time.
function checkemail(){
var EmailFromForm = $("#lostemail").val();
var EmailCheckRes = $.ajax({
type : "POST",
cache : false,
url : "./scripts/passreset/emailcheck.php",
data : "Email="+EmailFromForm,
dataType : "text",
}).responseText;
if (EmailCheckRes == "true")
{
alert("Should say true: " + EmailCheckRes);
return true;
}
else
{
$("#ErrorMsg").html("Your email address is either invalid or not found.");
alert("Should say false: " + EmailCheckRes);
return false;
}
}
If anyone has any pointers as to what i'm doing wrong it'd be greatly appreciated.
© Stack Overflow or respective owner