Skip to content
Advertisement

How to get a certain line from xml from other webpage (url) in js?

JavaScript

I’m trying to request a xml page from a page, but i’m unable to get certain line from xml in javascript. Thank you!

Advertisement

Answer

You can easily send requests to other pages with an AJAX http request found here: https://www.w3schools.com/js/js_ajax_intro.asp

Here is an example function:

JavaScript

Now, about getting a value from the xml document, you can use .getElementsByTagName(). Notice that this is an array of elements so you have to append an index such as [0]
This would go inside the onreadystatechange of the http request

JavaScript

So if the xml document had an element like:

JavaScript

the function would print Hello

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement