📄 ajax.js
字号:
// JScript 文件
function $n()
{
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementsByName(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}
String.prototype.trim=function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
var Request = new Object();
Request.reqList = [];
function getAjax(){
var ajax=false;
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = false;
}
}
if (!ajax && typeof XMLHttpRequest!='undefined') {
ajax = new XMLHttpRequest();
}
return ajax;
}
Request.send = function(url, method, callback, data, urlencoded, callback2,load) {
var req=getAjax();
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status < 400) {
if(callback)
{
(method=="POST") ? callback(req,data) : callback(req,data);
}
} else {
alert(url);
alert("There was a problem loading data :\n" + req.status+ "/" + req.statusText);
if (callback2) {
callback2(req,data);
}
}
try {
delete req;
req = null;
} catch (e) {}
}
}
if (method=="POST") { req.open("POST", url, true); if (urlencoded) req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); req.send(data); Request.reqList.push(req); } else { req.open("GET", url, true); req.send(null); Request.reqList.push(req); }
if(!load)
{
loading();
}
return req;
}
Request.clearReqList = function() {
var ln = Request.reqList.length;
for (var i=0; i<ln; i++) {
var req = Request.reqList[i];
if (req) {
try {
//req.close();
delete req;
} catch(e) {}
}
}
Request.reqList = [];
}
Request.sendPOST = function(url, data, callback, clear, callback2,load) {
if (clear)
Request.clearReqList();
Request.send(url, "POST", callback, data, true, callback2,load);
}
Request.sendGET = function(url, callback, args, clear, callback2,load) {
if (clear)
Request.clearReqList();
return Request.send(url, "GET", callback, args, false, callback2,load);
}
function loading()
{
if($("result"))
$("result").innerText="正在查询,请稍候...........";
else if($("content"))
$("content").innerText="正在查询,请稍候...........";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -