javascript - read a text file and show its data in text box -
this question has answer here:
- how read local text file? 9 answers
please assist me new java scripting. want show data text file in "d:\vikas.txt" path text box.if can provide me complete code helpful.i using google chrome browser. in case need other info please let me know.
thanks
you can use http request , file static page.
function exec_req(url) { objajax = false; if (window.xmlhttprequest) { try { objajax = new xmlhttprequest(); if (objajax.overridemimetype) objajax.overridemimetype('text/xml'); } catch(e) { objajax = false; } } else if (window.activexobject) { try { objajax = new activexobject("msxml2.xmlhttp"); } catch(e) { try { objajax = new activexobject("microsoft.xmlhttp"); } catch(e) { objajax = false; } } } if (objajax) { objajax.onreadystatechange = mycallback; } objajax.open("get", url, true); objajax.send(); } } function mycallback() { if(objajax.readystate == 4 && objajax.status == 200) { var mytext = objajax.responsetext alert(mytext) } else {alert('error while reading file');} }
just call function exec_req('bla/your_file _link.txt'), , when file'll read function mycallback invoked, , text looking available local var in function. async. not sure work locally if don't run localhost (cross origin requests supported http).
Comments
Post a Comment