javascript - XMLHttpRequest to .js file -
i trying experiment codes. send xmlhttprequest javascript file have document.write('hello world'); , use code in head section of html document:
<script> function loadxmldoc() { var xmlhttp; if (window.xmlhttprequest) { xmlhttp = new xmlhttprequest(); } else { xmlhttp = new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readystate == 4 && xmlhttp.status == 200) { document.getelementbyid("mydiv").innerhtml = xmlhttp.responsetext; } } xmlhttp.open("get", "java.js", true); xmlhttp.send(); } </script> and in java.js there single line of code
document.write('hello world'); what expect result should 'hello world' prints whole line document.write('hello world');. there way 'hello world' responsetext? using files. know can done using php/asp or text file challenge college days before 2 years when student using javascript file , still don't have dear how this. want know excellent brains of world on stack overflow.
the way evaling response , know side-effects of using eval.
replace xmlhttp.responsetext eval(xmlhttp.responsetext) , should work.
note: use caution while evaling!
just sure not send markup <script> in response eval not have desired effect then.
Comments
Post a Comment