How to parse XML from another server using JavaScript or jQuery?

Go To


I am new to Javascript. I need to parse XML using javascript or jQuery which is another server. I tried by using the below code. But when I executed it, it was not going to success method.

I was able to parse the XML which is in the same folder. Is it possible in javascript to access content from another server. I read the Same Origin Policy.

I was able to get the success message, but cant get the xml data


type: 'GET',
url: '',  
dataType: "xml",

success: function(data){
    $(data).find("Node").each(function() {

    error: err  

function err(xhr, reason, ex)
    alert('xhr.status: ' + xhr.status);
    alert('ex "'+ex);
2012-04-04 06:58
by Abi


You cannot load something from another server due to cross-domain security checks.

However for javascript, there is a workaround: the JSONP technique:

It is used for JSON data but it can just as well be used for any string data. But it will only work if you have some degree of control (i.e. can install a script) on that server.

Another alternative is to proxy that URL on your own server. That might be easier.

2012-04-04 08:22
by Wouter Lievens
How to proxy URL to my serve - Abi 2012-04-04 08:35
Create a dynamic page (PHP, java, whatever your backend is) on your server that fetches the XML file from the other server over HTTP, and then sends that data to your client. Check out this question on SO: - Wouter Lievens 2012-04-04 14:15