-1

I want to make ZIP file by ajax and download.

in PHP(makezip.php) ZIP file is dynamically generated.

http://exmaple.com/myzip.zip

How can I download by javascript???

in javascript

function download(){
    $.ajax({
      url:  http://example.com/makezip.php // to Ajax
      type: 'POST',
      dataType: 'json',
      data: {'id' : id}
    }).then(
        function(data) {
//How should I do here for download???
//         var blob = new Blob([ "http://exmaple.com/myzip.zip" ], { "type" : "zip" });
//         let link = document.createElement('a');
//         link.href = window.URL.createObjectURL(blob);
//         link.download = 'myzipname.zip';
 //         link.click();
      }
    );
};
whitebear
  • 11,200
  • 24
  • 114
  • 237
  • Possible duplicate of [Download a file by jQuery.Ajax](https://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax) – Reetesh Kumar Jun 28 '19 at 06:12

1 Answers1

1

You can do,

window.location.href = your_zip_file_path;

It will redirect to the next tab or it will download.

Rahul
  • 18,271
  • 7
  • 41
  • 60