当前位置:编程学习 > 网站相关 >>

Ajax五步使用法

AjaxClient.html:

[html] 
<html> 
<head> 
    <title>ajaxClient</title> 
    <script type="text/javascript"> 
        var xmlhttp; 
        function submit()  
        { 
            if(window.XMLHttpRequest) 
            { 
            //IE7 above,firefox,chrome^^ 
                xmlhttp=new XMLHttpRequest(); 
                //为了兼容部分Mozillar浏览器,当来自服务器响应开头不是xml,导致的无法响应问题 
                if(xmlhttp.overrideMimeType) 
                { 
                    xmlhttp.overrideMimeType('text/xml'); 
                } 
            } 
            else if(window.ActiveXObject) 
            { 
                //IE5\IE6 
                xmlhttp=new activeXObject("Microsoft.XMLHTTP"); 
            } 
            if(xmlhttp==null||xmlhttp==undefined) 
            { 
                alert("con't create XMLHttpRequest Object"); 
            } 
            var userName = document.getElementById('testText').value; 
            //注册回调函数 
            xmlhttp.onreadystatechange = callback; 
            //发送信息 
            xmlhttp.open('GET','AjaxServer.aspx?name='+userName,true); 
            xmlhttp.send(null); 
                 
        } 
        function callback()  
        { 
            //判断交互是否完成,是否正确返回 
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)  
            { 
                //获取服务器返回信息 
                var message = xmlhttp.responseText; 
                //得到提示信息div 
                var testDiv=document.getElementById('test'); 
                testDiv.innerHTML=message; 
            } 
        } 
    </script> 
</head> 
<body> 
    <!--用户名输入框--> 
    <input type="text" name="wenben" value="" id="testText" /> 
    <input type="button" name="ceshi" value="submit" onclick="submit();" /> 
    <!--用于显示提示信息--> 
    <div id="test"></div> 
</body> 
</html> 

<html>
<head>
 <title>ajaxClient</title>
 <script type="text/javascript">
     var xmlhttp;
     function submit()
        {
      if(window.XMLHttpRequest)
      {
      //IE7 above,firefox,chrome^^
       xmlhttp=new XMLHttpRequest();
       //为了兼容部分Mozillar浏览器,当来自服务器响应开头不是xml,导致的无法响应问题
       if(xmlhttp.overrideMimeType)
       {
        xmlhttp.overrideMimeType('text/xml');
       }
      }
      else if(window.ActiveXObject)
      {
       //IE5\IE6
       xmlhttp=new activeXObject("Microsoft.XMLHTTP");
      }
      if(xmlhttp==null||xmlhttp==undefined)
      {
       alert("con't create XMLHttpRequest Object");
      }
      var userName = document.getElementById('testText').value;
      //注册回调函数
      xmlhttp.onreadystatechange = callback;
      //发送信息
      xmlhttp.open('GET','AjaxServer.aspx?name='+userName,true);
      xmlhttp.send(null);
    
     }
        function callback()
        {
         //判断交互是否完成,是否正确返回
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
            {
                //获取服务器返回信息
     

补充:Web开发 , 其他 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,