-4

Need to download the remote file into browser using javascript. I am having the url of the file. Download must happen in background

1 Answers1

-1

No, JavaScript doesn't have access to writing files as this would be a huge security risk.

see Read/write to file using jQuery

IF you want to simply download the content and use it in the script, using jQuery it's very simple:

https://api.jquery.com/jQuery.ajax/

jQuery.ajax({
    url: "your/file/here",
    dataType: 'text',   // you can also use xml, json, html here
    success : function(data) {
        console.log(data);
    },
    error : function(xhr, textStatus, errorThrown) {
        console.log("ERROR: "+textStatus+", "+errorThrown);
    },
    async: true
});
Community
  • 1
  • 1
ivicaa
  • 605
  • 1
  • 6
  • 17
  • i done that using jquery. Now i need to make download without showing that to the user to the specified location – user3318686 Mar 25 '14 at 18:02
  • What do you mean with "to the specific location"? Writing to the file system? This won't work with JavaScript (see above). – ivicaa Mar 25 '14 at 19:12