I'm doing a simple database validation. To avoid duplicate names, I want to see if the First and Last names are in the database and alert the user before writing the data. So I've got an ASP page that works fine. It returns the count of records where FName like 'xxx%' and LName like 'yyy%'. Running it alone it works great, so no problems there.
Calling it is a JS/Ajax call here:
When I call it, the return value is always "undefined" (if I store it/view it in a var). With the following, I almost always get "not found", whether the name exists or not.:
I've changed the Open to synch which helped once, but it's not consistent. Am I missing something or is there a better way to make it wait to return until XmlHttp.status is 200?
Thanks.
Calling it is a JS/Ajax call here:
Code:
var sUrl = "Includes/CommonLogic_ExistingName.asp";
sUrl = sUrl + "?sFirst=" + sFirst;
sUrl = sUrl + "?sLast=" + sLast;
sUrl = sUrl + "&sid=" + Math.random();
oXmlHttp.onreadystatechange = function() {
if (oXmlHttp.readyState == 4)
{
if (oXmlHttp.status == 200)
{
var sTemp = oXmlHttp.responseText;
if (sTemp.length > 0)
{
if (sTemp > 0)
{
return true;
}
else
{
return false;
}
}
}
}
}
oXmlHttp.open("GET", sUrl, false);
oXmlHttp.send(null);
Code:
function func_TestNewName()
{
if (func_IsExistingName(txtFName.value, txtLName.value) == true)
{
alert("This name already exists.");
} else {
alert("This name was not found");
}
}
I've changed the Open to synch which helped once, but it's not consistent. Am I missing something or is there a better way to make it wait to return until XmlHttp.status is 200?
Thanks.