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

In general, can you get an XML file from an API using JavaScript?

  • I understand that most api's would prevent you from accessing them with javascript because of security problems, but are there ways around that? EDIT: I'm sorry, this question is particularly about one API, the http://legiscan.com/legiscan api, which seems to be adverse to access using javascript, jquery, etc.

  • Answer:

    If they don't have any technique for accessing the data in a cross-domain way, like CORS (Cross Origin Resource Sharing) or JSONP, then the best way to handle this is to just create your own proxy on your own domain to access the API. Just have a small server that just forwards your JavaScript's Ajax requests over to the API, and returns the response that it provides.

Clarence Leung at Quora Visit the source

Was this solution helpful to you?

Other answers

Sure. JQuery is particularly adept at this. You can specify the type of data the jQuery GET call receives from the server.

Marc Gottlieb

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.