Start uploading file after ajax call is completed

$.ajax({
                    type: "POST",
                    url: "processform.php",
                    dataType: "json",
                    data: {name: name, email: email, city: city, country: country, day: day, month: month, year: year}
                    }).done(function(msg){

                        if(msg.success == 1){
                            $("#success_msg").append('<p>'+msg.message+'</p>');
                            window.location.href = './music/song.mp3';
                        }

                    });

The code above loads a new page using the music player. I want it to load as a file.

+3
source share
4 answers

You can do this through PHP, create a PHP file with the correct headers and redirect to this page, this will force the browser to download the file.

<?php
header('Content-disposition: attachment; filename=song.mp3');
header('Content-type: audio/mpeg3');
readfile('song.mp3');
?>
+3
source

try doing this:

header("Content-Disposition: attachment; filename=somefile.mp3;");
+3
source

ajax, . -.

 $.ajax({
                type: "POST",
                url: "processform.php",
                dataType: "json",
                data: {name: name, email: email, city: city, country: country, day: day, month: month, year: year}
                }).done(function(msg){

                    if(msg.success == 1){
                        $("#success_msg").append('<p>'+msg.message+'</p>');
                       // window.location.href = './music/song.mp3';
                        $('<a/>', {target:'_blank', href:'./music/song.mp3'}).appendTo($("#success_msg")).html('Click To Download <Filename>');
                    }

                });
+1

. -, , .

0

All Articles