我的网站最近从server03 转到了server08上,结果ajax提交就不能用了。。。
1 var net=new Object(); 2 //编写构造函数 3 net.AjaxRequest=function(url,onload,onerror,method,params){ 4 this.req=null; 5 this.onload=onload; 6 this.onerror=(onerror) ? onerror : this.defaultError; 7 this.loadDate(url,method,params); 8 } 9 //编写用于初始化XMLHttpRequest对象并指定处理函数,最后发送HTTP请求的方法 10 net.AjaxRequest.prototype.loadDate=function(url,method,params){ 11 if (!method){ 12 method="GET"; 13 } 14 if (window.XMLHttpRequest){ 15 this.req=new XMLHttpRequest(); 16 } else if (window.ActiveXObject){ 17 this.req=new ActiveXObject("Microsoft.XMLHTTP"); 18 } 19 if (this.req){ 20 try{ 21 var loader=this; 22 this.req.onreadystatechange=function(){ 23 net.AjaxRequest.onReadyState.call(loader); 24 } 25 26 this.req.open(method,url,true); 27 if(method=="POST"){ 28 this.req.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 29 } 30 alert(encodeURI(params)); 31 // alert(encodeURI(params)); 32 this.req.send(params); 33 }catch (err){ 34 alert("hahahhaha"); 35 this.onerror.call(this); 36 } 37 } 38 } 39 40 //重构回调函数 41 net.AjaxRequest.onReadyState=function(){ 42 var req=this.req; 43 var ready=req.readyState; 44 if (ready==4){ 45 if (req.status==200 ){ 46 this.onload.call(this); 47 }else{ 48 alert(nihaoaoaoao); 49 this.onerror.call(this); 50 } 51 } 52 } 53 //重构默认的错误处理函籹 54 net.AjaxRequest.prototype.defaultError=function(){ 55 alert("error fetching data!" 56 +"\n\nreadyState:"+this.req.readyState 57 +"\nstatus: "+this.req.status 58 +"\nheaders: "+this.req.getAllResponseHeaders()); 59 }
就是出error这个问题,弹出
defaultError这块
请您帮忙看看
你不妨了解一下jsonp 跨域