ozgeneral
ozgeneral

Reputation: 6819

Get method do not work with a download URL

I am trying to get a HTML request work. I have an URL in the following format:

abc.def.com/download?fileid=123&entity_id=123&sid=123

When it is clicked, it directly downloads a file. Instead of downloading, I am trying to get it with an HTML request, and process it with code later on. The following works when I set urlString to any website, however it returns nothing when I use the actual URL. What might be cause of this? Is there something that prevents me to request a download link content?

var urlString = "http://abc.def.com/download?fileid=123&entity_id=123&sid=123";

$.get(urlString, function(data, status){
alert("Data: " + data + "\nStatus: " + status);});

Note: not sure if it is relevant but the file itself is in proprietary format.

Upvotes: 1

Views: 428

Answers (1)

shreyas
shreyas

Reputation: 2630

you can not read a response from cross origin request i.e it is not allowed to call a url of different domain from via ajax. For security purposes browsers does not allow javascript to do that.

for details please read https://en.wikipedia.org/wiki/Same-origin_policy

EDIT: for completeness putting info from comments

this SO question lists extensive ways to go around it

Upvotes: 1

Related Questions