Access an XML file from different domain in JS

Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
Posts: 106

Access an XML file from different domain in JS

I am creating a website with HTML and JavaScript that relies on the data of an XML file hosted on a separate domain.
I can achieve this with jQuery-Ajax if the XML is in the same domain as my HTML page, but I cannot find a solution when the file is on a different domain.
Any ideea of how can i read a file from different domain using JavaScript in html page (Not server side)?

Try using the the fetch api.

Code: Select all

.then( response => response.text() )
.then( response => {
  //response is a string containing xml...
  document.getElementById('elm_id').innerHTML = response;
.catch( console.error );
I thing you don't need to serialize the xml, you should just be able to put it directly... but not sure.

Similar Topics