首页 > Web开发 > 详细

XMLHttpRequest函数封装

时间:2016-09-13 16:08:03      阅读:146      评论:0      收藏:0      [点我收藏+]

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);
				}
			}
		}
	}
}

  

XMLHttpRequest函数封装

原文:http://www.cnblogs.com/handsomehan/p/5868531.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!