日期:2014-05-18  浏览次数:20545 次

ajax有时不执行
现在是第一次加载页面后可以执行,但第2次如果文本框中的值没有变化就不会调用,自己用alert跟踪到代码中的位置停止,是啥毛病?头一次写纯代码的ajax.

function   amountCheck(){
var   Invoice=document.getElementById( "txtInvoice ").value;
if(Invoice   ==   " "){
alert( "Please   Input   Inovie! ");
document.getElementById( "txtInvoice ").focus();
return   false;
}
var   amount=document.getElementById( "txtAmount ").value;
var   due=document.getElementById( "txtDue ").value;
var   jobNo=document.getElementById( "txtJobNumber ").value;
sendAJAX( 'amountCheck.aspx?Amount= '+amount+ '&Due= '+due+ '&JobNo= '+jobNo);
}


function   sendAJAX(url)
{
if   (window.XMLHttpRequest)
{
    IE=false;
    XmlHttp=new   XMLHttpRequest();
}
else   if   (window.ActiveXObject)
{
IE=true;
              try   {
          XmlHttp=   new   ActiveXObject( "Msxml2.XMLHTTP ");
}
catch   (e1)
{
try   {
  XmlHttp   =   new   ActiveXObject( "Microsoft.XMLHTTP ");
}   catch   (e2){alert(e2);}
        }
    }
     
  var     pUrl=url;
XmlHttp.open( "POST ",pUrl,true);
XmlHttp.send(null);
//**************************         直到这里都可以正常执行
XmlHttp.onreadystatechange=ServerProcess;
}

function   ServerProcess()
{  
alert( "Process...... ");
if   (XmlHttp.readyState==4   ||   XmlHttp.readyState== 'complete ')
{
ShowDialog(XmlHttp.responseText);
}
}

------解决方案--------------------
你在哪里调用amountCheck()方法的?
看你似乎在做自动完成?

你的文本框又用了什么事件
如果是onchange 事件调用了结果肯定是这样的

你将Text的onchange事件改为
onkeydown= "amountCheck(); " onkeyup= "amountCheck(); " 两个事件
------解决方案--------------------
记得 结贴
------解决方案--------------------
debugger 还是debugger
------解决方案--------------------
<input name= "button " type= "button " value= "Insert Refrence " class= "form-button " onkeydown= "amountCheck(); " onkeyup= "amountCheck(); " Width= "110px "/>

------解决方案--------------------
if (XmlHttp.readyState==4 || XmlHttp.readyState== 'complete ')
{
ShowDialog(XmlHttp.responseText);
}
这个不对吧
if (XmlHttp.readyState==4 && XmlHttp.readyState==200)
{
ShowDialog(XmlHttp.responseText);
}