Search code examples
javascriptblobepubxmlhttprequest

XMLHttpRequest with a file from a 3rd party server


First of all, forgive my english please..

Is it possible to retrieve a file using a xmlhttp GET Request with the url parameter that is an address to a file not located in the server, but in another server?

<script>
var request = new XMLHttpRequest();
request.open("GET", "url/of/file.epub", true);
request.responseType = "blob";
request.onload = function () {
    new Epub(request.response, function (bookData) {
        Monocle.Reader("reader", bookData);
    });
};
request.send();
</script>

In the example above an XMLHttpRequest has been made to return a blob


Solution

  • No, it's not possible. You can use the forcecors plugin for Firefox to have FF ignore the same origin policy (because all responses have cors headers).

    The other option would be JSONP but since you've already mentioned blob data it isn't an option since JSONP only works with JS.