how load .txt file using ajax? found how load xml files.
this have far:
function loadtxt(url) { var xmlhttp; var txt; if (window.xmlhttprequest) { // code ie7+, firefox, chrome, opera, safari xmlhttp = new xmlhttprequest(); } else { // code ie6, ie5 xmlhttp = new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate == 4 && xmlhttp.status == 200) { document.getelementbyid("phones").innerhtml=xmlhttp.responsetext; } xmlhttp.open("get","folder",true); xmlhttp.send(); } }
and then:
<form name="phonebook"> <p id="phones"></p> <input type="button" onclick="loadtxt()" value="click"> </form>
but nothing happens. first time working ajax, detailed answer appreciated.
you haven't opened connection server using
xhr.open("get", urltoyourtextfile, true);
after connection open, must call send() send request.
Comments
Post a Comment