CodeIgniter的force_download()问题 [英] CodeIgniter's force_download() problems

查看:167
本文介绍了CodeIgniter的force_download()问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试生成一个.json文件,以便在Ajax调用中使用CodeIgniter的force_download()下载,但是无法正常工作.

I'm trying to generate a .json file to download using CodeIgniter's force_download() in an Ajax call, but it doesn't work as expected.

这是我的Ajax电话:

Here is my Ajax call:

$.ajax({
    url: /myfunction, 
    type: 'POST', 
    data: {value_sent: my_json_array}
});

还有我的PHP函数:

public myfunction()
{
    $dl_array = $this->input->post("value_sent");
    $this->load->helper('download');
    force_download("file.json", $dl_array);
}

数据已发送(我已仔细检查),但从未显示下载提示.我认为force_download()失败,但是我不明白为什么.

Data is sent (I double checked), but download prompt is never shown. I assume force_download() fails, but I don't understand why.

非常感谢您的帮助!

推荐答案

这不是CodeIgniter的问题,它是JavaScript的局限性.您无法按照通过jQuery下载文件的方式通过AJAX下载文件.Ajax.

This isn't a problem with CodeIgniter, it's a limitation of JavaScript. You can't download files via AJAX, as referenced in Download a file by jQuery.Ajax.

您无法通过Ajax完成此操作,因为JavaScript无法保存文件 直接出于用户的考虑(出于安全考虑)

you can't do it through Ajax because JavaScript cannot save files directly to a user's computer (out of security concerns)

这篇关于CodeIgniter的force_download()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆