0

I am simply trying to read a html file inside a div, now it is not working therefore I tried to read just a a simple text file named a.txt, the text file contains 3 lines "asdasdas" something like that.

It just won't work, the function is being called after pressing a paragraph tag, here is the code:

functionNew()
{       
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }

    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("divfull").innerHTML = xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","a.txt",true);
    xmlhttp.send(null);

}

any ideas why its not working?

4

1 回答 1

0

代码似乎是正确的,但尝试调用

xmlhttp.open("GET","a.txt",true);

xmlhttp.onreadystatechange=function()

尝试让我们知道它是否适合您

于 2012-08-07T12:11:12.053 回答