1

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.

ozgeneral
  • 6,079
  • 2
  • 30
  • 45

1 Answers1

1

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

Community
  • 1
  • 1
shreyas
  • 2,510
  • 4
  • 19
  • 20
  • Is there a way to get around it? I can download it from the link so it should somehow be accessible to a code as well, right? – ozgeneral Jan 28 '16 at 12:38
  • Im currently trying the suggestions in the following link but could not make any suggestion work yet. http://stackoverflow.com/questions/15005500/loading-cross-domain-html-page-with-ajax – ozgeneral Jan 28 '16 at 12:40
  • if the domain you are calling is under your control than you can enable CORS https://en.wikipedia.org/wiki/Cross-origin_resource_sharing – shreyas Jan 28 '16 at 12:45
  • I dont have the control of the domain but at least now I know the problem, which gives me something to work on. Thanks. – ozgeneral Jan 28 '16 at 12:50