问题
I'm working on a non-blocking script and it's works fine but when i try to load jQuery, its loads but i cant execute jQuery functions like this simple alert:
$(document).ready(function(){
alert('jQuery loaded !');
});
Here is what im trying:
var xhrObj = XMLHttpRequest();
xhrObj.onreadystatechange =
function(){
if(xhrObj.readyState == 4){
var element = document.createElement("script");
document.getElementsByTagName('head')[0].appendChild(element);
element.text = xhrObj.responseText;
}
};
xhrObj.open('GET', 'js/jquery.js', true);
xhrObj.send('');
and tried it too:
var js = document.createElement('script');
js.src = 'js/jquery.js';
var head = document.getElementsByTagName('head')[0];
head.appendChild(js);
Here is the result of Firebug error:
ReferenceError: $ is not defined
$(document).ready(function(){
but when i check Firebug network, jQuery is loaded....
Need some help.. Thanks !
来源:https://stackoverflow.com/questions/15855149/non-blocking-script-not-working-with-jquery