|
本帖最后由 iginter 于 2024年1月4日 19:00 编辑
JS复制代码 $('#downfile').click(function(){ $.post(' downloadtpl'); }); 到echo $data这·一行运行是正常的,浏览器能显示文本中的内容;但把下面两句注释去掉后执行,没有任何反应,浏览器调试,发现执行也是200,搜索N多,不明白是哪里有问题,新入CI请指教 | |
|
PHP复制代码 public function downloadtpl() { $filePath01 = 'uploads/tpls/tpl.txt'; if (file_exists ($filePath01)) { $data = file_get_contents ($filePath01); $this->load->helper('download'); force_download('stockTpl.txt', $data, 'application/octet-stream'); } else { show_error('bad file'); } } 试试这样可以吗? | |
|
| |
js部分改成
本帖最后由 qq291561792 于 2024年2月23日 17:23 编辑
$.post(' downloadtpl'); 改成 if ( $('#iframe_box').length == 0 ){ var tmpdiv = document.createElement('div'); tmpdiv.id = 'iframe_box'; tmpdiv.style='width:1px; height:1px;'; document.body.appendChild(tmpdiv); } var iframe = document.createElement('iframe'); iframe.src = "downloadtpl"; iframe.width = 1; iframe.height = 1; $("#iframe_box").find('iframe').remove(); $("#iframe_box").get(0).appendChild(iframe); | |