zoukankan      html  css  js  c++  java
  • XMLHttpRequest函数封装

    XMLHttpRequest函数封装:

    function ajax(Url,sccuessFn,failureFn) {
    	//1.创建XMLHttpRequest对象
    	var xhr = null;
    	if(window.XMLHttpRequest) {
    		xhr = new XMLHttpRequest();
    	}else {
    		xhr = new ActiveXObject('Microsoft.XMLHTTP');
    	}
    	//2.打开与服务器的链接
    	xhr = open('get',Url,true);
    	//3.发送给服务器
    	xhr = send(null);
    	//4.响应就绪
    	xhr.onreadystatechange = function() {
    		if(xhr.readyState == 4) {
    			if(xhr.status == 200) {
    				successFn(xhr.responseText);
    			}else {
    				if(failureFn) {
    					failureFn();
    				}else {
    					alert(xhr.status);
    				}
    			}
    		}
    	}
    }
    

      

  • 相关阅读:
    学习Timer定时器
    C++ 延时等待(sleep/timer/wait)
    MFC学习问题总结
    node.js
    总结
    关于Windows
    关于数组
    每周一次
    每周一次
    每周一次
  • 原文地址:https://www.cnblogs.com/handsomehan/p/5868531.html
Copyright © 2011-2022 走看看