ajax - XML into browser using GET HTTP request -
could give exmaple of simple code retrieve xml data browser api available on different server via http.
i struggling around cross origin issues using xmlhttprequest. unsure whether should try around these issues or if there alternative solution.
the code reside locally (on pc)
<!doctype html> <html> <head> <script> function loadxmldoc() { var xmlhttp; 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("mydiv").innerhtml=xmlhttp.responsetext; } } xmlhttp.open("get","my url",true); xmlhttp.send(); } </script> </head> <body> <h2>ajax</h2> <button type="button" onclick="loadxmldoc()">request data</button> <p>click button several times see if time changes, or if file cached.</p> <div id="mydiv"></div> </body> </html>
Comments
Post a Comment