Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在ajax调用完成后开始下载文件 $.ajax({ 类型:“POST”, url:“processform.php”, 数据类型:“json”, 数据:{name:name,email:email,city:city,country:country,day:day,month:month,year:year} }).done(函数(msg){ 如果(msg.success==1){ $(“#success_msg”).append(“_Jquery - Fatal编程技术网

Jquery 在ajax调用完成后开始下载文件 $.ajax({ 类型:“POST”, url:“processform.php”, 数据类型:“json”, 数据:{name:name,email:email,city:city,country:country,day:day,month:month,year:year} }).done(函数(msg){ 如果(msg.success==1){ $(“#success_msg”).append(“

Jquery 在ajax调用完成后开始下载文件 $.ajax({ 类型:“POST”, url:“processform.php”, 数据类型:“json”, 数据:{name:name,email:email,city:city,country:country,day:day,month:month,year:year} }).done(函数(msg){ 如果(msg.success==1){ $(“#success_msg”).append(“,jquery,Jquery,”+msg.message+””); window.location.href='./music/song.mp3'; } }); 上面的代码只是加载了一个带有音乐播放器的新页面。我希望它像文件一样下载。这取决于浏览器。如果您的浏览器有媒体插件,它可能会直接在浏览器中打开媒体文件,而不是提供下载对话框。请尝试以下方法: $.ajax({ type: "POST", url: "processform.php",

”+msg.message+”

”); window.location.href='./music/song.mp3'; } });
上面的代码只是加载了一个带有音乐播放器的新页面。我希望它像文件一样下载。

这取决于浏览器。如果您的浏览器有媒体插件,它可能会直接在浏览器中打开媒体文件,而不是提供下载对话框。

请尝试以下方法:

$.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';
                        }

                    });

你可以通过PHP来实现,创建一个具有正确标题的PHP文件,然后重定向到该页面,它将强制浏览器下载该文件

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

如果在ajax调用后放弃自动下载, 你可以这样做。浏览器将以自己的方式处理这种情况

<?php
header('Content-disposition: attachment; filename=song.mp3');
header('Content-type: audio/mpeg3');
readfile('song.mp3');
?>
$.ajax({
类型:“POST”,
url:“processform.php”,
数据类型:“json”,
数据:{name:name,email:email,city:city,country:country,day:day,month:month,year:year}
}).done(函数(msg){
如果(msg.success==1){
$(“#success_msg”).append(“”+msg.message+”

”); //window.location.href='./music/song.mp3'; $('',{target:''u blank',href:'./music/song.mp3'}).appendTo($(“#success_msg”).html('点击下载'); } });
pecl\u http中的http\u send\u文件非常有用-为自动304(未修改)响应启用范围请求和http\u match\u etag。和@Adam在处理输出之前,请将内容类型设置为某个值,以便浏览器下载
 $.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>');
                    }

                });