zoukankan      html  css  js  c++  java
  • 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请求,今天在学习发现的问题,具体为什么本人也不知道,如有知情者还望指教




  • 相关阅读:
    C#项目打包,并自动安装SQL数据库(转)
    [转]将List对象列表转换成JSON格式的类
    查找算法集:顺序查找、二分查找、插值查找、动态查找(数组实现、链表实现)
    C#编码好习惯
    数据库构思与设计规范
    ASP.NET下母版页和内容页中的事件发生顺序整理
    记录要点
    div挡住select的5种方法
    html源码获取方法
    TransactionScope 分布式事务
  • 原文地址:https://www.cnblogs.com/chaofan/p/1679075.html
Copyright © 2011-2022 走看看