1

Basically I have found a way without exit (I am sure there has to be a way) to request a file using JS.

As you know, you cannot request files from a server (e.g. a shared file in google drive) because the access-control-allow-origin security issue.

On the other hand, you cannot access to the disk files because the client-side security issue as well.

In such a case, how I can manage to read a xml file using JS? How I can load that file?

I have tried to create CROS requests as responded in some other question, but unless I have understood bad, this solution requires anyway modify the server settings and I don't have access to the server (as could guess for the beginning the idea was get a file from google drive or dropbox).

So again, how can I manage to get that file either from a server or from my local disk?

Thank you a lot

iseji
  • 80
  • 6
  • You can always request files from your *own* server (domain), the SOP and CORS are only relevant when talking to other hosts. – Bergi Mar 10 '15 at 21:47
  • 2
    You might try looking here. http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy – whoacowboy Mar 10 '15 at 21:54

1 Answers1

0

The short and unsatisfying answer is: You simply cannot.

Javascript in the browser is sandboxed. The security mechanisms are there for a reason, and you cannot circumvent them to my knowledge.

If you need to pull a xml file from a server and have no possibility to change that host to implement CORS for you, then you have some options. Here are two of them:

  • You could use e.g. Apache's reverse proxy directives to "strap" the service you want to access underneath the webpage you develop. This way, the same origin policy does no longer stand in your way.
  • You could use some server side language on the webpage that will do the same for you: query the foreign host and prepare the data to be consumed the way you want it.
Kai Mattern
  • 3,090
  • 2
  • 34
  • 37
  • Ok. I can see that cannot do it directly as I was suspecting. I like the aproach that you propose of use some server side language to query the content and serve it to my app. Thanks a lot, I was out of ideas. – iseji Mar 10 '15 at 22:29