⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ajaxclass.js

📁 ajax动态树菜单
💻 JS
字号:
// JavaScript Document

// 这个文件你可能连看的必要性都不存在,不用明的,只要会用

function ajaxClass(){

this.error404='';
this.error403='';
this.error400='';

this.ifnotready='';


this.onGet='';


this.onPost=''; 
this.postContent="";
this.http_message="ready";
this.error=false;
this.method="GET";
this.url;
this.async=true;


   
   var http_request = false;
	try{
	  if (window.XMLHttpRequest) { 
			http_request = new XMLHttpRequest();
			}
	  else if (window.ActiveXObject) { 
			try {http_request = new ActiveXObject("Msxml2.XMLHTTP");}
			   catch (e) {
			        try {http_request = new ActiveXObject("Microsoft.XMLHTTP");}catch (e) {};}
      if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/xml');
			};
	  };
	}catch(e){this.http_message="你的浏览器太旧了,请尽快更新0";this.error=true;return false;};
   if(!http_request){this.http_message="你的浏览器太旧了,请尽快更新";this.error=true;return false;};
   
   var objSelf=this;


   this.sendRequest=function () {
	   try{
	       if(!objSelf.method||!objSelf.url||!objSelf.async) return false; 

		   if(objSelf.method=="GET"){
				  http_request.open("GET",objSelf.url, true);
				  http_request.onreadystatechange =function () { 
					  try{     
						  if (http_request.readyState == 4) {
		
							  if (http_request.status == 200){ if(objSelf.onGet!="")eval(objSelf.onGet);
							  }else if(http_request.status==404){if(objSelf.error404!="")eval(objSelf.error404);}
							   else if(http_request.status==403){if(objSelf.error403!="")eval(objSelf.error403);}
									 else{if(objSelf.error400!="")eval(objSelf.error400);};	
							}else{if(objSelf.ifnotready!="")eval(objSelf.ifnotready);};
					   }catch(e){objSelf.error=true;objSelf.http_message="服务器处理时出错";};
				  };http_request.send(null);
			}else if(objSelf.method=="POST"){
			      http_request.open ("POST", objSelf.url, true);
				  http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");                  http_request.onreadystatechange=function () { 
					  try{     
						  if (http_request.readyState == 4) {
				
							  if (http_request.status == 200){ if(objSelf.onPost!="")eval(objSelf.onPost);
							  }else if(http_request.status==404){if(objSelf.error404!="")eval(objSelf.error404);}
							   else if(http_request.status==403){if(objSelf.error403!="")eval(objSelf.error403);}
									 else{if(objSelf.error400!="")eval(objSelf.error400);};	
							}else{if(objSelf.ifnotready!="")eval(objSelf.ifnotready);};
					   }catch(e){objSelf.error=true;objSelf.http_message="服务器处理时出错";};
				  };http_request.send(objSelf.postContent);
			}else {objSelf.error=true;objSelf.http_message="method not support";};
	   }catch(e){objSelf.error=true;objSelf.http_message="发送请求失败";};
   }
   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -