www.webdeveloper.com
Results 1 to 2 of 2

Thread: How To Display XMLHttpRequest?

Hybrid View

  1. #1
    Join Date
    Oct 2008
    Posts
    12

    How To Display XMLHttpRequest?

    hi

    what's wrong with this code? it seems to load the text file ok, but it won't display it:
    Code:
    <script type="text/javascript"> 
    var client = new XMLHttpRequest(); 
    client.open('GET', 'resources/text/test.txt'); 
    document.write(client.responseText); 
    </script>
    thanks

  2. #2
    Join Date
    Oct 2006
    Posts
    939
    HTML Code:
    <script type="text/javascript"> 
    function yourfunc(url){
        oxmlhttp = null;
        try{        oxmlhttp = new XMLHttpRequest();        oxmlhttp.overrideMimeType("text/xml");    }
        catch(e){
            try{      oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");        }
            catch(e){          return null;        }
        }
        if(!oxmlhttp) return null;
        try{       oxmlhttp.open("GET",url,false);       oxmlhttp.send(null);    }
        catch(e){       return null;    }
    	document.getElementById('tx').value=oxmlhttp.responseText;
    }
    </script> 
    call yourFunc('resources/text/test.txt')

    it writes to textarea id="tx" so you can see it as code

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles