XMLHttpRequest 对象与属性
来源:互联网 发布:喷淋塔计算软件 编辑:程序博客网 时间:2024/05/16 04:53
XMLHttpRequest 对象用于在后台与服务器交换数据。
小例子
方法属性open()onreadystatechangesetRequestHeader()statussend()readyStategetResponseHeader()statusTextgetAllResponseHeaders()responseText responseXML responseBody responseStream 最后还有一个abort方法,用于取消当前请求.
1 //初始化XMLHttpRequest对象 2 var xhr=null; 3 var textName=null; 4 var infoTag=null; 5 //创建XmlHttpRequest对象并返回 6 function CreateXMLHttpRequest(){ 7 var xmlHttp; 8 if(window.XMLHttpRequest){ 9 xmlHttp=new XMLHttpRequest();10 } 11 else if(window.ActiveXObject){12 xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');13 }14 return xmlHttp;15 }16 //异步检查用户名是否存在17 function Check(){18 textName=document.getElementById('user');19 infoTag=document.getElementById('info');20 var sendData='userName='+textName.value;21 if(textName.value!=""){22 xhr=CreateXMLHttpRequest();23 xhr.onreadystatechange=CallBack_ShowData; 24 xhr.open('Post','Server_php/ServerCheck.php',true);25 //post方式需要下面两句设置Header26 xhr.setRequestHeader("content-length",sendData.length);27 xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 28 //要POST的数据 29 xhr.send(sendData);30 }31 else{32 infoTag.innerHTML='请输入用户名';33 }34 }35 function CallBack_ShowData(){36 if(xhr.readyState == 4){37 if(xhr.status==200){38 var data=xhr.responseText;39 //如果用户名存在则清空user,并使其获得焦点40 if(data.split('|')[1]=='Error'){41 textName.value='';42 textName.focus(); 43 }44 //不存在则让下一输入框获得焦点45 else{46 infoTag.focus();47 }48 //显示异步传输过来的数据49 infoTag.innerHTML=data.split('|')[0];50 }51 }52 }
- XMLHttpRequest 对象与属性
- XMLHttpRequest 对象的方法与属性
- XMLHttpRequest 对象的方法与属性
- ajax XMLHttpRequest 对象 的属性与方法
- XMLHttpRequest 对象的方法与属性
- XMLHttpRequest 对象的方法与属性
- XMLHttpRequest 对象的方法与属性
- XMLHttpRequest对象的属性与方法
- XMLHttpRequest对象的属性
- XMLHttpRequest对象readyState属性
- XMLHttpRequest对象的属性
- XMLHttpRequest对象readyState属性
- xmlHttpRequest对象的属性
- Ajax 中 XMLHttpRequest对象的方法与属性
- 常用的XmlHttpRequest对象属性
- XMLHttpRequest对象的方法、属性
- XmlHttpRequest对象介绍及属性
- XmlHttpRequest 对象的重要属性
- Visual Studio 用正则表达式查找替换
- 常用的CSS 属性
- C#字符串
- hdoj 3681 Prison Break
- 图书封面的故事之——“巴别塔”选自《七周七语言:理解多种编程范型》
- XMLHttpRequest 对象与属性
- [Jamendo] AlbumAdapter 之 getView
- C语言使用过程中遇到的问题
- Android 布局 UI
- js复习之-函数
- ASP.NET MVC 請問如何取得上一個網址
- MediaPlayer的基本使用
- 图书封面的故事之“阿尔特温人”——选自《Erlang/OTP并发编程实战》图书封面
- nexus工作目录设置