查一下req.readState和req.status的状态

解决方案 »

  1.   

    这个JS是存在的,另外,我在req.open("GET", url, true);后边有一个测试用的alert("test");如果这个URL是一个一般文件的话,就没有问题,可以读出网页内容,如果是js的话就不行了,这个alert也不执行,不知是怎么一回事
      

  2.   

    function loadXMLDoc(url) {
        // branch for native XMLHttpRequest object
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send(null);
        // branch for IE/Windows ActiveX version
        } else if (window.ActiveXObject) {
            isIE = true;
            req = new ActiveXObject("Microsoft.XMLHTTP");
            if (req) {
                req.onreadystatechange = processReqChange;
                req.open("GET", url, true);
    alert(111);
                req.send();
    return(req.responseText);
            }
        }
    }
    function processReqChange() {
        // only if req shows "loaded"
        if (req.readyState == 4) {
            // only if "OK"
            if (req.status == 200) {
             } else {
                alert("There was a problem retrieving the XML data:\n" +
                    req.statusText);
             }
        }
    }
      

  3.   

    我也是参考的别的代码,就是不能获取JS文件,如果把这个URL换成一个JS地址就不行了