最基础的AJAX脚本技术例子

GET数据提交方式
js 代码
 
  1.   
  2.     <script language="javascript" type="text/javascript">   
  3.   
  4. //实现分页功能   
  5. // 异步传输   
  6. function gread_list(){   
  7.     var content=document.getElementById("nianji_list");   
  8.   
  9.     //创建浏览器兼容的XMLHttpRequest对象   
  10.     var xmlhttp;   
  11.     try{   
  12.         xmlhttp= new ActiveXObject(Msxml2.XMLHTTP);   
  13.     }catch(e){   
  14.         try{   
  15.             xmlhttp= new ActiveXObject(Microsoft.XMLHTTP);   
  16.         }catch(e){   
  17.             try{   
  18.                 xmlhttp= new XMLHttpRequest();   
  19.             }catch(e){}   
  20.         }   
  21.     }   
  22.        
  23.     //定义XMLHttpRequest对象的事件处理程序   
  24.     xmlhttp.onreadystatechange=function(){   
  25.         if(xmlhttp.readyState==4){   
  26.             //关闭显示条   
  27.   
  28.             if(xmlhttp.status==200){   
  29.                 //当加载成功时将内容显示于页面,并清空表单   
  30.                 content.innerHTML="1";   
  31.     //          content.innerHTML=xmlhttp.responseText;   
  32.         //      clearmsg();                 
  33.                 alert(xmlhttp.responseText);   
  34.             }else{   
  35.                 //否则弹出错误信息   
  36.                    
  37.                 alert(xmlhttp.status);   
  38.                      
  39.             }   
  40.         }   
  41.     }   
  42.     //创建一个连接   
  43.     var page=form1.xueqi.options.value;   
  44.     xmlhttp.open("get","ajax_inquire_grade.aspx?gread_id="+page);   
  45.     //发送请求   
  46.     xmlhttp.send(null);   
  47.   
  48. }   
  49.         </script>  

POST数据提交方式
js 代码
 
  1.   
  2.     <script language="javascript" type="text/javascript">   
  3.   
  4. //实现分页功能   
  5. // 异步传输   
  6. function gread_list(){   
  7.     var content=document.getElementById("nianji_list");   
  8.   
  9.     //创建浏览器兼容的XMLHttpRequest对象   
  10.     var xmlhttp;   
  11.     try{   
  12.         xmlhttp= new ActiveXObject(Msxml2.XMLHTTP);   
  13.     }catch(e){   
  14.         try{   
  15.             xmlhttp= new ActiveXObject(Microsoft.XMLHTTP);   
  16.         }catch(e){   
  17.             try{   
  18.                 xmlhttp= new XMLHttpRequest();   
  19.             }catch(e){}   
  20.         }   
  21.     }   
  22.        
  23.     //定义XMLHttpRequest对象的事件处理程序   
  24.     xmlhttp.onreadystatechange=function(){   
  25.         if(xmlhttp.readyState==4){   
  26.             //关闭显示条   
  27.   
  28.             if(xmlhttp.status==200){   
  29.                 //当加载成功时将内容显示于页面,并清空表单   
  30.                 content.innerHTML="1";   
  31.     //          content.innerHTML=xmlhttp.responseText;   
  32.         //      clearmsg();                 
  33.                 alert(xmlhttp.responseText);   
  34.             }else{   
  35.                 //否则弹出错误信息   
  36.                    
  37.                 alert(xmlhttp.status);   
  38.                      
  39.             }   
  40.         }   
  41.     }   
  42.     //创建一个连接   
  43.     xmlhttp.open("POST",url,true);   
  44. xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");   
  45. t="Text="+Text;//参数列表   
  46. xmlhttp.send(t);   
  47.   
  48. }   
  49.         </script>  


文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
评论: 0 | 引用: 0 | 查看次数: 1893
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭