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

📄 ajaxed.js

📁 javasrcipt编写的Ajax的类库
💻 JS
字号:
function ajaxed() {}

ajaxed.prototype.indicator = document.createElement('div');

//registers the loading indicator
Ajax.Responders.register({
	onCreate: function() {
		s = ajaxed.prototype.indicator.style;
		s.background = "#cc0000";
		s.color = "#fff";
		s.position = "absolute";
		s.right = "4px";
		s.top = "4px";
		if (Ajax.activeRequestCount == 1) document.body.appendChild(ajaxed.prototype.indicator);
	},
	onComplete: function() {
		if (Ajax.activeRequestCount == 0) document.body.removeChild(ajaxed.prototype.indicator);
	}
});

//optional: onComplete, url (because of bug in iis5 http://support.microsoft.com/kb/216493)
ajaxed.callback = function(theAction, func, params, onComplete, url) {
	if (params) {
		params = $H(params);
	} else {
		if ($('frm')) {
			params = $H($('frm').serialize(true));
		} else {
			params = $H({});
		}
	}
	params.merge({PageAjaxed: theAction});
	uri = window.location.href;
	if (ajaxed.prototype.debug) ajaxed.debug("Action (to be handled in callback):\n\n" + theAction);
	if (uri.endsWith('/') && url) uri += url;
	new Ajax.Request(uri, {
		method: 'post',
		parameters: params,
		requestHeaders: {Accept: 'application/json'},
		onSuccess: function(trans) {
			if (ajaxed.prototype.debug) ajaxed.debug("Response on callback:\n\n" + trans.responseText);
			if (!trans.responseText.startsWith('{ "root":')) {
				ajaxed.callbackFailure(trans);
			} else {
				if (func) func(trans.responseText.evalJSON(true).root);
			}
		},
		onFailure: ajaxed.callbackFailure,
		onComplete: onComplete
	}); 
}
ajaxed.callbackFailure = function(transport) {
	friendlyMsg = transport.responseText;
	friendlyMsg = friendlyMsg.replace(new RegExp("(<head[\\s\\S]*?</head>)|(<script[\\s\\S]*?</script>)", "gi"), "");
	friendlyMsg = friendlyMsg.stripTags();
	friendlyMsg = friendlyMsg.replace(new RegExp("[\\s]+", "gi"), " ");
	alert(friendlyMsg);
}
ajaxed.debug = function(msg){
	alert("<DEBUG MESSAGE>\n\n" + msg);
}

⌨️ 快捷键说明

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