Created
August 14, 2012 16:23
-
-
Save hqmatics/3350607 to your computer and use it in GitHub Desktop.
jQuery split into smaller files and load with ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function microAjax(url, callbackFunction) { | |
this.bindFunction = function (caller, object) { | |
return function() { | |
return caller.apply(object, [object]); | |
}; | |
}; | |
this.stateChange = function (object) { | |
if (this.request.readyState==4) | |
this.callbackFunction(this.request.responseText); | |
}; | |
this.getRequest = function() { | |
if (window.ActiveXObject) | |
return new ActiveXObject('Microsoft.XMLHTTP'); | |
else if (window.XMLHttpRequest) | |
return new XMLHttpRequest(); | |
return false; | |
}; | |
this.postBody = (arguments[2] || ""); | |
this.callbackFunction=callbackFunction; | |
this.url=url; | |
this.request = this.getRequest(); | |
if (this.request) { | |
var req = this.request; | |
req.onreadystatechange = this.bindFunction(this.stateChange, this); | |
if (this.postBody!=="") { | |
req.open("POST", url, false); | |
req.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); | |
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | |
req.setRequestHeader('Connection', 'close'); | |
} else { | |
req.open("GET", url, false); | |
} | |
req.send(this.postBody); | |
} | |
} | |
var jquerysource = ''; | |
microAjax("/js/jquerypart1.txt", function (res) { jquerysource =res; }); | |
microAjax("/js/jquerypart2.txt", function (res) { jquerysource+=res; }); | |
eval(jquerysource); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment