日期:2014-05-16  浏览次数:20314 次

XMLHTTP JS错误 类型不匹配
<script   language= "javascript "   >
var   xmlHttp   =   false;
try   {
    xmlHttp   =   new   ActiveXObject( "Msxml2.XMLHTTP ");
}   catch   (e)   {
    try   {
        xmlHttp   =   new   ActiveXObject( "Microsoft.XMLHTTP ");
    }   catch   (e2)   {
        xmlHttp   =   false;
    }
}
if   (!xmlHttp   &&   typeof   XMLHttpRequest   !=   'undefined ')   {
    xmlHttp   =   new   XMLHttpRequest();
}

function   average(t_id)  
{
var   key1
var   key2
eval(key1   =   eval( "document.form1.Txt_key1_ "+   t_id   + ".value; "));
eval(key2   =   eval( "document.form1.Txt_key2_ "+   t_id   + ".value; "));
var   url   =   "key_value.asp?Txt_id= "+   t_id   + "&Txt_key1= "+key1+ "&Txt_key2= "+key2;
    xmlHttp.open( "GET ",   url,   true);
    xmlHttp.onreadystatechange   =   updatePage(t_id);
    xmlHttp.setRequestHeader( "Content-Type ",   "application/x-www-form-urlencoded ");
    xmlHttp.send();  
}

function   updatePage(t_id)  
{
    if   (xmlHttp.readyState   <   4)
    {
document.form1.Txt_msg_1215.value   =   "数据加载中…… "
    }
    if   (xmlHttp.readyState   ==   4)  
    {
        var   response   =   xmlHttp.responseText;
document.form1.Txt_msg_1215.value=response;
    }
}

</script>


注:
updatePage(t_id)里面的1215本来是想换成t_id的。但为了测试方便,统一用一个文本框了。


现在这个JS的一触发

就会提示这样的错误:

行:29
字符:3
错误:类型不匹配
代码:0


第29行为:

    xmlHttp.onreadystatechange   =   updatePage(t_id);


哪位兄弟姐妹帮帮我。

TKS




------解决方案--------------------
xmlHttp.onreadystatechange = updatePage(t_id);

updatePage(t_id);是一个返回值

xmlHttp.onreadystatechange 需要的是一个函数