关于ajax的一点疑问
关于ajax的一点疑问<div id="cnblogs_post_body">今天在调试程序的时候发现了一个奇怪的问题,我写了一个封装ajax的对象,名字就叫ajax:
<div class="cnblogs_code"> 1 var ajax = { 2 get : function(url, onOk) { 3 var xmlHttpRequest = this.createXMLHttpRequest(); 4 xmlHttpRequest.open("GET", url, true); 5 xmlHttpRequest.onreadystatechange = function() { 6 if (this.readyState == 4) { 7 if (this.status == 200) { 8 onOk(responseText); 9 } else {10 onOk("异步通信失败");11 }12 }13 };14 xmlHttpRequest.send(null);15 },16 post : function(url, param, onOk) {17 var xmlHttpRequest = this.createXMLHttpRequest();18 xmlHttpRequest.open("POST", url, true);19 xmlHttpRequest.onreadystatechange = function() {20 if (this.readyState == 4) {21 if (this.status == 200) {22 onOk(responseText);23 } else {24 onOk("异步通信失败");25 }26 }27 };28 xmlHttpRequest.send(param);29 },30 createXMLHttpRequest : function() {31 if (window.XMLHttpRequest) {32 return new XMLHttpRequest();33 } else if (window.ActiveXObject) {34 return new ActiveXObject("Microsoft.XMLHTTP");35 }36 }37 };
页:
[1]