Non blocking script not working with jQuery

十年热恋 提交于 2019-12-13 03:39:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!