Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.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/1/php/232.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
Javascript 我能';t获取用于将phpspreadsheet文件保存到本地磁盘的文件位置弹出窗口_Javascript_Php_Phpspreadsheet - Fatal编程技术网

Javascript 我能';t获取用于将phpspreadsheet文件保存到本地磁盘的文件位置弹出窗口

Javascript 我能';t获取用于将phpspreadsheet文件保存到本地磁盘的文件位置弹出窗口,javascript,php,phpspreadsheet,Javascript,Php,Phpspreadsheet,用户应该能够将生成的excel工作表保存到自己选择的本地位置。 这是打开生成excel文件的php文件的javascript代码 <script> function exportWeek() { var $radios = document.getElementsByName('wasbeurt'); for (var i = 0, length = $radios.length; i < length;

用户应该能够将生成的excel工作表保存到自己选择的本地位置。 这是打开生成excel文件的php文件的javascript代码

    <script>
        function exportWeek() {
            var $radios = document.getElementsByName('wasbeurt');
            for (var i = 0, length = $radios.length; i < length; i++) {
                if ($radios[i].checked) {
                    $wasbeurt = $radios[i].value// do whatever you want with the checked radio
                    break;
                }
            }
            $str = 'sdatum='+document.getElementById("startdatum").value;
            $str = $str + '&duo='+document.getElementById("chauffeursduo").value;
            $str = $str + '&kmstart='+document.getElementById("kilometerstandstart").value;
            $str = $str + '&kmeind='+document.getElementById("kilometerstandeind").value;
            $str = $str + '&wasbeurt='+$wasbeurt;
            if (window.XMLHttpRequest) {
                // script for browser version above IE 7 and the other popular browsers (newer browsers)
                xmlhttp = new XMLHttpRequest();
            } else {
                // script for the IE 5 and 6 browsers (older versions)
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function() {
                if (this.readyState === 4 && this.status === 200) {
                  // get the element in which we will use as a placeholder and space for table
                }
            };
            xmlhttp.open("GET", "exportweek.php?"+$str, false);
            xmlhttp.send();
        }
    </script>
如果取消对exit语句上方的行的注释,则生成的excel文件将正确保存在该目录中。 保存('php://output)在这里不起作用


有什么建议吗?

您没有收到下载弹出窗口,因为您在此处提出后台请求。您没有收到下载弹出窗口,因为您在此处提出后台请求。
    // Redirect output to a client’s web browser (Xlsx)
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="Weekstaat.xlsx"');
    //header('Content-Disposition: attachment;filename="'.$fileName.'"');
    header('Cache-Control: max-age=0');
    // If you're serving to IE 9, then the following may be needed
    //header('Cache-Control: max-age=1');
    
    // If you're serving to IE over SSL, then the follfing may be needed
    // header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    // header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
    // header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
    // header('Pragma: public'); // HTTP/1.0
    ob_clean();
    $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
    $writer->save('php://output');
    //$writer->save('G:\Temp\Export\Weekstaat.xlsx');
    exit;