2

I've read that there is no way that JQuery can download a file directly, so far I was handling the situation by using iframes which worked perfectly for my situation. But now, the requirement has changed, and the file creation is being protected with authentication. I need a way to send the authorization header along with the iframe src request or some other way to do this, since ajax is not an option. And I want to keep this as a single step, any ideas of how to handle this?

BTW ... PHP scripts are not an option.

Thank you

Mike
  • 485
  • 1
  • 4
  • 14

1 Answers1

3

You don't specify which kind of authentication is in use, but for basic authentication you can try accessing the URL like this:

http://username:password@example.com

This will send the header without the need to set anything using jQuery.

Keep in mind that doing something like this client-side, jQuery or not, exposes the credentials.

Telmo Marques
  • 5,066
  • 1
  • 24
  • 34
  • Right, it is basic authentication. The thing is that I am already authenticated, I just need to send the authorization token to the service that creates and returns the file. – Mike Mar 29 '12 at 19:21
  • @Mike, what do you mean by authorization token? – Telmo Marques Mar 29 '12 at 19:36
  • 1
    After login, I get an access token which is used to access the other services without sending the credentials again, only by using the token on the authorization header. – Mike Mar 29 '12 at 20:45
  • @Mike, I don't think that's possible, at least not without server-side code. Please see this question: http://stackoverflow.com/questions/3047711/custom-http-request-headers-in-html – Telmo Marques Mar 29 '12 at 21:54