1

Is there a way to get the epub file from a uri which download a epub file automatically using ajax request. Sample link would be http://www.bookrix.com/Books/Download.html?bookID=bx.dickens_1276691363.9406330585&format=epub. Currently Im getting the file on the server side and can show it using epubreader but I want to use the file on the client side and place it in the epubreader. I get this error when I run the ajax request. Ive tryed to change the headers with no luck. XMLHttpRequest cannot load . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

$.ajax({
    type: 'GET',
    url: 'http://www.bookrix.com/Books/Download.html?bookID=bx.dickens_1276691363.9406330585&format=epub',
    dataType: 'application/xml',
    crossDomain: true,
    beforeSend: function(request) {
        request.setRequestHeader('Access-Control-Allow-Origin', "*");
        request.setRequestHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
        request.setRequestHeader('Content-Type', 'GET');
    },
    success: function (result) {
        window.alert("success!!");
    },
    error: function (exception) {
        window.alert("something wrong!" + exception);
    }
}).error(function(data) {
    console.log('Error:', data);
});

$(document).ready(function() {
    $("#btnSubmit").click(function() {
        alert("button");
        console.log("jtest");
    });
});

Iv'e implemented rack::cors with no success

rallesport
  • 28
  • 4
  • `Access-Control-Allow-Origin` et al are **response** headers, not *request* headers. The `www.bookrix.com` server has to set them, not your client side JavaScript. – Quentin Jun 06 '16 at 10:58
  • Is there any work around in html? I really dont want to store epubfiles on a server!. Im using epubjs right know and it works perfectly if I unzip the epub file and place it in the reader. The only thing I need is the epub file after that I will try to figure out how to unzip it. – rallesport Jun 06 '16 at 11:57
  • No, there absolutely is not. That would make the entire security feature useless. – Quentin Jun 06 '16 at 12:32

1 Answers1

0

I'm trying to open your example link:

https://www.epubbooks.com/downloads/3836

And i'm stumble upon the following error on that website:

Access denied.

So you're trying to retrieve a file/link, that's only accessible when you're logged in. There doesn't seem to be a public API to properly retrieve data.

Your only shot would be contacting the developer of that website, Michael Cook. You could ask if it's possible to use an API (if it exists) to retrieve data from that service.

Check the About me-section: https://www.epubbooks.com/about

MHX
  • 1,581
  • 2
  • 21
  • 31
  • Thanks for replying! Sorry for that didn't notice that I was logged in to the site. But I change the link to http://www.bookrix.com/Books/Download.html?bookID=bx.dickens_1276691363.9406330585&format=epub. It is for test purpose only. I am using another api which gives me a uri link like the one I posted above. – rallesport Jun 05 '16 at 21:35