1

I'd like to know if it's possible to load a remote XML file through the <script> tag, and access the content using JavaScript.

As the XML is a result of an external website (I'm using TheTVDb API), I can't load it using AJAX.

I'm looking for something like the following, if it's possible (JQuery-like syntax):

<script id="xmlload" type="text/xml" src="...">
<script type="text/javascript">
  var xmlcontent = $('#xmlload').content();
  // parse xmlcontent
</script>
4
  • 1
    what error are you getting? is the xml not ready? if so, maybe try doing it on document.ready Commented Feb 29, 2012 at 9:28
  • 1
    yes in jquery it is possible to fetch the xml, json content Commented Feb 29, 2012 at 9:40
  • No, the XML is hosted on a remote server. Commented Feb 29, 2012 at 9:41
  • 1
    Please use upvote to thank and do not thank in question. Commented Sep 25, 2013 at 12:08

1 Answer 1

2

I don't think that this is possible - you will need to use XmlHttpRequest (AJAX) to use a HTTP-based API. However, it might still be possible to actually do cross-site requests if the TheTVDb server allows this - see HTTP access control on MDN, which describes the relevant W3C specification (Cross-Origin Resource Sharing).

So if you haven't done so yet, I'd recommend you just try if making an AJAX request works. Otherwise, it might be a good idea to ask the TheTVDb folks if they are so kind to implement the mentioned spec.

Sign up to request clarification or add additional context in comments.

2 Comments

The cross-site request is not a problem, as I'm building a Chrome packaged application, which allows to make cross-site requests.
I don't understand the problem, then. If you can make cross-site requests, why shouldn't you be able to do an XmlHttpRequest to any server? Have you tried?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.