Ajax在firefox中的奇怪表现

1 <form name="registF" method="post" action="#">
2 <p>注册名称:<input type="text" name="user" /><span id="check"></span></p>
3 <p>注册密码:<input type="password" name="pwd" /></p>
4 <p><input type="submit" name="sbm" value="注册" id="sbm" /></p>
5 </form>
6 <button id="test">Ajax测试</button>

 

上面是一个很普通的表单

我们要运用Ajax来检查名称是否被注册过

于是:

 1 var xhr = {
 2     cxhr:new XMLHttpRequest() || new ActiveXObject('Msxml2.XMLHttp'|| new ActiveXObject('Microsoft.XMLHttp'),
 3     request:function(method,url,callback,postVars){
 4         xhr.cxhr.onreadystatechange = function(){
 5             if(xhr.cxhr.readyState != 4return;
 6             (xhr.cxhr.status == 200? 
 7             callback.success(xhr.cxhr.responseText,xhr.cxhr.responseXML):
 8             callback.failure(xhr.cxhr.status);
 9             }
10         xhr.cxhr.open(method,url,true);
11         if(method != 'POST' || method != 'post'){
12                 postVars = null;
13             }
14         xhr.cxhr.send(postVars);
15         }
16     }
17     
18 window.onload = function(){
19      var callback = {
20          success:function(responseText,responseXML){document.getElementById('check').innerHTML = responseText;alert(responseText);},
21          failure:function(statusCode){alert("Failure" + statusCode);}
22      };
23      document.getElementById('sbm').onclick = function(){
24         xhr.request('GET',"test.php",callback);
25         }
26     }

在ff中运行为:

修改一下:

1 window.onload = function(){
2      var callback = {
3          success:function(responseText,responseXML){document.getElementById('check').innerHTML = responseText;alert(responseText);},
4          failure:function(statusCode){alert("Failure" + statusCode);}
5      };
6      document.getElementById('test').onclick = function(){
7         xhr.request('GET',"test.php",callback);
8         }
9     }

 

再运行一下:


就是说ff不能在提交表单时进行Ajax请求,今天在学习发现的问题,具体为什么本人也不知道,如有知情者还望指教




posted on 2010-03-05 12:55  铁拐李  阅读(1168)  评论(2编辑  收藏  举报