View Code
//MIXINS
//module pattern
//I define a function and then immediately execute it within it's own private bubble (function context)
(function () {
//Data Retrieval
var XMLHttpFactories = [
function () { return new XMLHttpRequest() },
function () { return new ActiveXObject('Msxml2.XMLHTTP') },
function () { return new ActiveXObject('Msxml3.XMLHTTP') },
function () { return new ActiveXObject('Microsoft.XMLHTTP') }
];
function createXMLHTTPObject() {
var xmlhttp = false;
for (var i = 0; i < XMLHttpFactories.length; i++) {
try {
xmlhttp = XMLHttpFactories[i]();
} catch (ex) {
continue;
}
break;
}
return xmlhttp;
}
/*
{String} url
{Boolean} postData
{Callback} callback
*/
function sendRequest(url, postData, callback) {
var req = createXMLHTTPObject();
if (!req) return;
var method = (postData) ? 'POST' : 'GET';
req.open(method, url, true);
req.setRequestHeader('User-Agent', 'XMLHTTP');
if (postData) {
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
}
req.onreadystatechange = function () {
if (req.readyState != 4) return;
if (req.status != 200 && req.status != 304) {
alert('Http error ' + req.status);
return;
}
callback(req);
};
if (req.readyState == 4) return;
req.send(postData);
}
/*var RetrievalData = function () {};
RetrievalData.prototype.ajax = sendRequest;*/
var RetrievalData = {
ajax: sendRequest
};
//逃出闭包
window.Data = RetrievalData;
})();
//module pattern
//I define a function and then immediately execute it within it's own private bubble (function context)
(function () {
//Data Retrieval
var XMLHttpFactories = [
function () { return new XMLHttpRequest() },
function () { return new ActiveXObject('Msxml2.XMLHTTP') },
function () { return new ActiveXObject('Msxml3.XMLHTTP') },
function () { return new ActiveXObject('Microsoft.XMLHTTP') }
];
function createXMLHTTPObject() {
var xmlhttp = false;
for (var i = 0; i < XMLHttpFactories.length; i++) {
try {
xmlhttp = XMLHttpFactories[i]();
} catch (ex) {
continue;
}
break;
}
return xmlhttp;
}
/*
{String} url
{Boolean} postData
{Callback} callback
*/
function sendRequest(url, postData, callback) {
var req = createXMLHTTPObject();
if (!req) return;
var method = (postData) ? 'POST' : 'GET';
req.open(method, url, true);
req.setRequestHeader('User-Agent', 'XMLHTTP');
if (postData) {
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
}
req.onreadystatechange = function () {
if (req.readyState != 4) return;
if (req.status != 200 && req.status != 304) {
alert('Http error ' + req.status);
return;
}
callback(req);
};
if (req.readyState == 4) return;
req.send(postData);
}
/*var RetrievalData = function () {};
RetrievalData.prototype.ajax = sendRequest;*/
var RetrievalData = {
ajax: sendRequest
};
//逃出闭包
window.Data = RetrievalData;
})();