-1

Dynamically I've created a link with download attribute:

var link = $('<a>', {
  href:file_url, 
  download:file_name
}).appendTo('body');

By clicking on that link programmably I want to download a file with given file name.

Is it possible to trigger GET request by clicking on that link by jQuery?

I know about jquery.fileDownload.js plugin, but I need to set a file name on client side not on server side.

megas
  • 21,401
  • 12
  • 79
  • 130
  • Precisely what do you mean by 'trigger GET' request? Do you mean an ajax request? – reggaemahn Aug 15 '13 at 10:06
  • Have a look at [How to trigger the default action/event of a HTML link (anchor element)?](http://stackoverflow.com/q/7186165/218196) – Felix Kling Aug 15 '13 at 10:08
  • @FelixKling, yes, but opening the window will generate file with default name 'download' or something – megas Aug 15 '13 at 10:11
  • @JeevanJose, just clicking on element is not making GET request to server – megas Aug 15 '13 at 10:12
  • possible duplicate of [JavaScript: Invoking click-event of an anchor tag from javascript](http://stackoverflow.com/questions/980709/javascript-invoking-click-event-of-an-anchor-tag-from-javascript) – cmbuckley Aug 15 '13 at 10:24

1 Answers1

0

I hope I understand your question correctly. You have a link and you want to generate a GET request on click. If this is correct then,

  • To generate the click, you can simply use

$('a').trigger('click');

  • About the GET, clicking a link by default generates a GET request to the server.
reggaemahn
  • 6,272
  • 6
  • 34
  • 59