How to get the file using it's URL in Javascript?

How to parse external XML file URL using JavaScript or Ajax?

  • hi i want to parse external XML file coming from another server which is not in local system using JavaScript or Ajax i have the code here <html> <head> <script type="text/javascript"> function getHttpObject() { var xmlhttp = null; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject) { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } else { alert("Your browser does not support XMLHTTP!"); } return xmlhttp; } function generategraph() { xmlhttp = getHttpObject(); xmlhttp.onreadystatechange = function() { alert(xmlhttp.status);//it is displaying 0 it means The server is not responding or is not reachable// if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { //ajxfrm.state.value=xmlhttp.responseT… alert(xmlhttp.responseText); } } xmlhttp.open("GET", "URL", true); xmlhttp.send(); } </script> </head> <body> <input type="button" value="GenerateGraph" onClick="generategraph();" > </body> </html> and i need to draw to draw graphs using that url after parsing actually i am getting an alert box as "0" this "0" is the xmlhttp.responseText in which i should get 200 please help me and in advance thank you

  • Answer:

    You might be having problems because of cross domain security restrictions. XML cannot be sent from one domain to another. So, if you are getting the XML from another web site you will not be able to use AJAX unless the other web site has set up security for cross domain and most have not. The reason for this is that XML can be used to attack another site. This is known as cross site scripting of XSS. Options 1. If possible use RESTful or JSON web services to get the same information 2. Get the XML from the server in your own applications server side program (e.g. a java servlet) and then pass the information onto your HTML file. This is called using a proxy server. 3. Use the popular library jquery to create cross domain ajax. http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/

hello at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.