封装ajax get请求,适用于异步获取js文件

function ajaxGetJs(url,callback){
    var xmlhttp;
    if (window.XMLHttpRequest){
        xmlhttp=new XMLHttpRequest();
    }else{
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET",url,false);
    xmlhttp.send();
    setInterval(fun,30);
    var flag=true;
    function fun(){
        if(xmlhttp.readyState==4 && xmlhttp.status==200 && flag){
            flag=false;
            eval(xmlhttp.responseText);
            callback();
        }
    }
}
if(!window.jQuery){
    ajaxGetJs("jquery.js",function(){
        console.log("加載完成");
    });
}else{
    console.log("已經存在jQuery");
}