猿问
下载APP

Script代码中xhr.open("GET", URL, true)说open is not a function

function ftn_button_clicked(){
              xhr = new createXHR();
                //var url="\PointGenerate";
                xhr.open("GET", "PointGenerate.java", true);          
                xhr.send();
                xhr.onreadystatechange = ajaxComplete;   
        }
        function ajaxComplete(){
            if(xhr.readyState === 4 && xhr.status === 200){
                    document.getElementById("txt1").innerHTML.value = xhr.responseText;
                    var num = xhr.responseText;
                    window.alert("good");
                    plotrandom(num); 
            }
        }
		  
       function createXHR(){
           if(window.XMLHttpRequest){
               xhr = new XMLHttpRequest();
               //window.alert("111"); check working or not
           }
           else{
               xhr = new ActiveXObject("Microsoft.XMLHTTP");
               //window.alert("1111");
           }

用游览器打开网页后,按按钮没反应, 就F12查看属性,游览器报错是这open那句话。 说is not a function. 

qq_Unbreak_03731269
浏览 6663回答 4
4回答

小羊杨

function ftn_button_clicked(){              xhr = createXHR();//此处直接赋值                //var url="\PointGenerate";                xhr.open("GET", "PointGenerate.java", true);                          xhr.send();                xhr.onreadystatechange = ajaxComplete;           }        function ajaxComplete(){            if(xhr.readyState === 4 && xhr.status === 200){                    document.getElementById("txt1").innerHTML.value = xhr.responseText;                    var num = xhr.responseText;                    window.alert("good");                    plotrandom(num);             }        }                  function createXHR(){            var xhr;//此处声明xhr变量           if(window.XMLHttpRequest){               xhr = new XMLHttpRequest();               //window.alert("111"); check working or not           }           else{               xhr = new ActiveXObject("Microsoft.XMLHTTP");               //window.alert("1111");           }            return xhr;//此处返回xhr对象        }如果你的问题已解决,请记得采纳答案!--copy from 李晓健 

yinyun

说明你没有正确初始化一个XMLHttpRequest对象

amorlova

xhr没有定义吧
打开App,查看更多内容
随时随地看视频慕课网APP
我要回答
继续浏览精彩内容
慕课网APP
程序员的梦工厂
继续