?? ajax.js
字號:
function ajax(url, method, callback, data, urlencoded, name) {
if(url.indexOf('?') > 0)
{
url += "&nocache=" + Math.random();
}
else
{
url += "?nocache=" + Math.random();
}
var req, durl, tries = 0;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (typeof name == "undefined") {
name = "";
} else {
name += "\n";
}
var readychange = function() {
if (req.readyState == 4) {// only if req shows "loaded"
if (req.status < 400) {// only if "OK"
var lm = null;
try {
lm = req.getResponseHeader("Last-Modified");
lm = new Date(lm);
} catch (e) { // workaround for Firefox 1.0.7
lm = new Date();
if (Math.random() > 0.8) {
lm -= 2400001;
}
}
method=="POST" ? callback(req) : callback(req,data);
} else if (typeof req == "undefined" || typeof req.status == "undefined") {
// don't do anything. user has navigated away
} else if (req.status == 401) { // unauthorized
callback(req);
} else if (req.status == 404) {
if (data && String(data).substr(0,4) == "feed") {
// cache miss
data = "";
do_request();
}
}
}
};
function do_request() {
if (++tries > 2) { // retry only twice
return false;
}
if (method=="POST") {
req.open("POST", url, true);
if (urlencoded) req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.onreadystatechange = readychange;
req.send(data);
} else {
durl = url;
req.open("GET", durl, true);
req.onreadystatechange = readychange;
req.send(null);
}
};
do_request();
return req;
}
function ajaxGet(uri,callback)
{
return ajax(uri,"GET",callback);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -