📄 request.js
字号:
/**
* Ajax 基本请求信息文件
* 作者: J li
*/
//处理浏览器,用来选择不同的XML读取函数
var agt = navigator.userAgent.toLowerCase();
var is_opera = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_opera;
var is_ie5 = (agt.indexOf("msie 5") != -1) && document.all;
var uniqnum_counter = (new Date).getTime();
var is_regexp = (window.RegExp) ? true : false;
var xmlhttp = null;
//为Get请求增加随机数,防止Cache
function UniqueNum() {
++uniqnum_counter;
return uniqnum_counter;
}
//创建Get请求
function StartGETRequest(url, handler)
{
xmlhttp = null;
if (is_ie) {
var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
try {
xmlhttp = new ActiveXObject(control);
} catch(e) {
alert("You need to enable active scripting and activeX controls");
DumpException(e);
}
} else {
xmlhttp = new XMLHttpRequest();
}
xmlhttp.onreadystatechange = function() {handler();}
if (url.indexOf("?") != -1){
var urltemp = url + "&rand=" + UniqueNum();
} else {
var urltemp = url + "?rand=" + UniqueNum();
}
//alert(urltemp);
xmlhttp.open('GET', urltemp, true);
xmlhttp.send(null);
}
//创建POST请求
function StartPOSTRequest(url, data, handler)
{
xmlhttp = null;
if (is_ie) {
var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
try {
xmlhttp = new ActiveXObject(control);
} catch(e) {
alert("You need to enable active scripting and activeX controls");
DumpException(e);
}
} else {
xmlhttp = new XMLHttpRequest();
}
xmlhttp.onreadystatechange = function() {handler();}
xmlhttp.open('POST', url, true);
//xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; Charset=GB2312"); // sending it as encoded formdata
//xmlhttp.setRequestHeader("Content-length", myText.length); // we need to specify the length of the contents
//xmlhttp.setRequestHeader("Connection","close"); // Connection is to be closed after transfer
if (typeof(xmlhttp.setRequestHeader) != "undefined") {
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; Charset=GB2312');
}
xmlhttp.send(data);
}
//处理方法
function GetObjValue(objName)
{
if(document.getElementById){
return eval('document.getElementById("' + objName + '")');
}else{
return eval('document.all.' + objName);
}
}
function fetchObject(idname)
{
if (document.getElementById) {
return document.getElementById(idname);
} else if (document.all) {
return document.all[idname];
} else if (document.layers) {
return document.layers[idname];
} else {
return null;
}
}
// function to emulate document.getElementsByTagName
function fetchTags(parentobj, tag)
{
if (typeof parentobj.getElementsByTagName != 'undefined') {
return parentobj.getElementsByTagName(tag);
} else if (parentobj.all && parentobj.all.tags) {
return parentobj.all.tags(tag);
} else {
return null;
}
}
function fetchXmlValue(parentobj, tag)
{
try{
var tags = fetchTags(parentobj, tag);
return tags[0].firstChild.nodeValue;
} catch(e) {
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -