<script id="fileTemplate" type="text/html">
    <li id="file<%=id%>">
         <input type="checkbox" value="<%=id%>">
        <i class="<%=type%>"></i>
        <span class="tit" title=""><%=oriname%></span>
        <span class="tool">
            <a href="" class="download" title="下载" data-id="<%=id%>"></a>
        </span>
        <span class="txt txt-time"><%=create_at%></span>
        <span class="txt txt-size"><%=filesize%></span>
    </li>
</script>// 下载
        $(document).on('click', '.download', function(){            file_id = $(this).attr('data-id');
            $.post('{:url('api/download', [], false)}', {
                file_id : file_id
            }, function(res) {                if(res.error_code !== 0) {
                    alert(res.reason);
                    return false;
                }
                window.open(res.result.downloadUrl);            }, 'json');
            return false;
        });================================
现在问题是点击下载是弹出一个页面显示内容。我想实现的效果是点击下载直接和我们去别的网站一样下载文件即可。不要弹出页面显示文件内容。

解决方案 »

  1.   

    是否产生下载对话框是由浏览器决定的:当浏览器不能识别返回数据的类型时
    所以你的 php 端要创造出这个条件
      

  2.   

    额,怎么创造  本人也是刚接触PHP 所以会问这问题。
      

  3.   

    下载路径 是否指向的个文件 例如 .apk 
    一般浏览器下载如果是应用程序之类的 都会直接下载
      

  4.   

    两处需要注意
    1,PHP输出的http,请在header中增加相应的type
    2,web容器请支持相应的type(如Apache支持apk下载,搜一下就知道怎么做)