I have some javascript code that sends an ajax request, but I get no response. How am I suppose to fix this? Thanks!
The Link I was trying to fetch is: http://research.engineering.wustl.edu/~todd/cse330/demo/lecture6/helloClass.txt
My code:
<!DOCTYPE html> <html> <head> <script type="text/javascript"> function sendRequest() { alert("Sending request"); var xmlHttp = new XMLHttpRequest(); xmlHttp.open("GET","http://research.engineering.wustl.edu/~todd/cse330/demo/lecture6/helloClass.txt",true); xmlHttp.addEventListener("load",ajaxCallback,false); xmlHttp.send(null); } function ajaxCallback(event) { alert("Here is the response " + event.target.responseText ); document.getElementById("demo").innerHTML= event.target.responseText; } </script> </head> <body> <h1>My Ajax Web Page</h1> <p id="demo">I will display something here</p> <form> <input name="submit" type=button value="Send Ajax Request" onClick="sendRequest()"> </form> </body> </html> Thank you for your answer. I just tried JSONP as you suggested, I use
<script type="text/javascript" src="http://research.engineering.wustl.edu/~todd/cse330/demo/lecture6/helloClass.txt?jsonp=parseResponse"> for my new script tag but still not work. Any furthur hint? Thanks!
Thank you all for your answer! But I'm new to this technique,so still abit confused. Would you mind bring more detail code for me to study. And I'm really interested in the agent listening method.