Home > Web Front-end > JS Tutorial > ajax asynchronous request post method

ajax asynchronous request post method

一个新手
Release: 2017-09-21 09:41:03
Original
2349 people have browsed it

<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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template