Home  >  Article  >  Web Front-end  >  ajax asynchronous request post method

ajax asynchronous request post method

一个新手
一个新手Original
2017-09-21 09:41:032313browse

<script>
//创建浏览器对象
function createXhr(){
 //判定浏览器类型处理第一种方法 
/*  var xhr;
 var str=window.navigator.userAgent;
 if(str.indexOf(&#39;MSIE&#39;)>0){
	xhr=new ActiveXObject(&#39;Microsoft.XMLHTTP&#39;);
 }else{
	xhr=new XMLHttpRequest();
 }
return xhr;
 */
 try{
	  return new ActiveXObject(&#39;Microsoft.XMLHTTP&#39;);
  }catch(e){
   }
  try{
	  return new XMLHttpRequest();
  }catch(e){
  }
   
};
//ajax Post请求
 	     var data="username=zs&&password=123456";
           var xhr=createXhr();
           xhr.onreadystatechange=function(){
        	    if(xhr.readyState==4&&xhr.status==200){
              };
           }
   		  xhr.open("post","/ajaxPost1");
   		  xhr.setRequestHeader(&#39;Content-type&#39;,&#39;application/x-www-form-urlencoded&#39;)
   	      xhr.send(data);
	 
</script>

The above is the detailed content of ajax asynchronous request post method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn