验证发送传真表单时,我正在检查传真是否已通过我们的软件传真包发送。这是对由脚本执行的表的简单查询,如果以前的传真存在,则返回一些文本,否则返回空白。为什么在xmlhttp.responseText之后没有设置变量?
我发现flag_stop_fax变量仍然设置为零,即使我有一些响应文本(例如:“传真已发送。”)。
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); // shows "0" even when I have a non-blank response from xmlhttp.responseText
还有一些其他的验证位,但上面的脚本有望解释这个问题。我不使用't'变量 - 这只是防止浏览器缓存。
那么,为什么我的flag_stop_fax设置为0呢?
AJAX是'Asynchronous'。您提醒您注意在回调代码之前运行。 – TheZ
首先回答这个问题 - Ajax中的A代表什么? – asawyer