随笔 - 20  文章 - 1  评论 - 159  阅读 - 71121

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   铁拐李  阅读(1173)  评论(2编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
< 2010年3月 >
28 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 1 2 3
4 5 6 7 8 9 10

点击右上角即可分享
微信分享提示