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

📄 xmlhttp.js

📁 几个运用了DWR框架编写的AJAX代码,
💻 JS
字号:
function XMLHttpClient(instanceName){	this.instanceName=instanceName;		this.xmlhttp = false;	if (window.XMLHttpRequest) { // Mozilla, Safari,...	   this.xmlhttp = new XMLHttpRequest();	   if (this.xmlhttp.overrideMimeType) {		   this.xmlhttp.overrideMimeType('text/xml');	   }	} else if (window.ActiveXObject) { // IE		try {			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");		} catch (e) {			try {				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");			} catch (e) {}		}	}	if (!this.xmlhttp) {		alert('无法创建组件:XMLHTTP,可能由于浏览器版本太低或浏览器部分组件已损坏。');	}}XMLHttpClient.prototype.open=function(method,url,Async){	this.xmlhttp.open(method,url,Async);	if (method == "POST"||method == "post") {		this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	}}XMLHttpClient.prototype.attachOnChange=function(instanceName){	this.xmlhttp.onreadystatechange=function()	{		if(window[instanceName].xmlhttp.readyState==4)		{			window[instanceName].fireOnStatus(window[instanceName].xmlhttp.status);		}	}}XMLHttpClient.prototype.getState=function(){	return this.xmlhttp.readyState;}XMLHttpClient.prototype.setRequestHeader=function(header,value){	this.xmlhttp.setRequestHeader(header,value);}XMLHttpClient.prototype.send=function(post_data){	this.xmlhttp.send(post_data);	this.attachOnChange(this.instanceName);}XMLHttpClient.prototype.attachOnStatus=function(Status,func){	this["onStatus_"+Status.toString()]=func;}XMLHttpClient.prototype.fireOnStatus=function(status){	if(this["onStatus_"+status])		this["onStatus_"+status](this.xmlhttp);	else		this["onStatus_default"](this.xmlhttp);}XMLHttpClient.prototype.onStatus_default=function(xmlhttp){	alert("通讯异常,错误号:"+xmlhttp.status.toString()+"!");}

⌨️ 快捷键说明

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