During the validation process of a send-fax form, I am checking if a fax has been previously sent using our software fax package. This involves a simple query to a table executed by a script, which will return text if a previous fax exists or blank if not.
I have noticed that the flag_stop_fax variable remains set at zero, even when there is a response text present (e.g., "A fax has already been sent.").
flag_stop_fax = 0;
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var response = xmlhttp.responseText;
if (response!='')
{
flag_stop_fax = 1;
alert(response);
}
}
}
xmlhttp.open('GET','/check_for_active_fax.php?fax_number=' + fax_number + '&t='+Math.random(),true);
xmlhttp.send();
alert(flag_stop_fax); // displays "0" even with non-empty response from xmlhttp.responseText
There are additional validation components associated with this issue, but the provided script should help highlight the underlying problem. The 't' variable serves as an anti-caching measure and isn't utilized for any specific purpose.
Hence, why is the flag_stop_fax variable failing to be assigned a value of 1?