-2

In the browser download.php?RID=189 works fine. i.e. loads and starts the download of the mp3 file.

but when called from an onclick, nothing happens. the data is populated ok and is successful but no download starts. do I need to do something with the data to make it start or change the way the php file is called? the php file is based on: http://davidwalsh.name/php-force-download

 function onApproveClick(clickVal) 
 {
    $.post("download.php",
    {
      RID: clickVal.value,
    },
    function(data,status){
      //  alert("Data: " + data + "\nStatus: " + status);

    }); 

 }  
user3725395
  • 145
  • 2
  • 13

1 Answers1

3

If you want to make the browser download a file, you cannot use an AJAX call. AJAX happens in the background, then the data is provided to your callback.

If you want to make the browser download a file, then you need to redirect it to your page:

function onApproveClick(clickVal){
    window.location = 'download.php?RID='+clickVal.value;
}

If your PHP page sends the correct headers, then the file will be downloaded and the user will remain on the current page.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337