Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.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/2/jquery/75.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
Php 使用1个ajax发送2个请求_Php_Jquery_Ajax_Twitter Bootstrap 3_Progress Bar - Fatal编程技术网

Php 使用1个ajax发送2个请求

Php 使用1个ajax发送2个请求,php,jquery,ajax,twitter-bootstrap-3,progress-bar,Php,Jquery,Ajax,Twitter Bootstrap 3,Progress Bar,我没什么问题 这是我的html <div class="row" style="margin-bottom: 10px;"> <div class="col-xs-1"> <span class="upload-excell btn btn-success" id="uploadExcellBtn"><i class="fa fa-upload"></i> Import Excel

我没什么问题

这是我的html

<div class="row" style="margin-bottom: 10px;">
            <div class="col-xs-1">
                <span class="upload-excell btn btn-success" id="uploadExcellBtn"><i class="fa fa-upload"></i> Import Excel</span>
                <div class="progress hidden" id="progress">
                    <div id="progressbat" class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="min-width: 2em; width: 0;">
                        0%
                    </div>
                </div>
            </div>
            <div class="col-xs-4">
                <input class="form-control filter" type="search" title="filter" placeholder="Search...">
            </div>
            <div class="col-xs-7"></div>
        </div>
<form class="Upload-form hiddenfile" method="post" enctype="multipart/form-data" action='upload url'>
    <input type="hidden" name="csrf_token" value="<?php echo $this->session->csrf_token; ?>" />
    <input type="file" name="file" class="excel-file"/>
</form>
这个代码是用来阅读的

set_time_limit(0);
        ob_implicit_flush(true);
        ob_end_flush();
        $xlsx = @(new SimpleXLSX($this->Session->new_file));
        $data = $xlsx->rows();
        $totalitems = count($data);
        $lastkey = $totalitems - 1;
        $current = 0;
        foreach ($data as $key => $val) {
            $current++;
            if ($key == 0 || $key == $lastkey) continue;
            // here I`m inserting in tho database
            sleep(1);
            $response = array(
                'loaded' => $current,
                'total' => $totalitems
            );
            echo json_encode($response);
        }

        sleep(1);
        unlink($this->Session->new_file);
        unset($this->Session->new_file);
        $response = array(
            'loaded' => $totalitems,
            'total' => $totalitems
        );
        echo json_encode($response);
上传的响应非常好
但是读取响应不起作用…

我用jquery ajax解决了这个问题。。
使用xhr参数…

为什么在完整的示例中使用js来处理ajax请求,而可以使用jquery?另外,为了可读性,我会把它放在一个单独的函数中。我不明白。。。你能给我示例代码如何做到这一点吗?我需要响应进度。。。所以我用的是ajax。。。据我所知,jquery无法获得响应进度。。。那么我该怎么做呢???我会按照这些思路做一些事情,
complete:function(){progressResponse()}
,并使用jquery
$.ajax
符号而不是简单的js.understand将ajax请求放在那里,但它不工作到。。。我在整个ajax代码中使用了一些自定义函数,但它不起作用。。。。我想它需要清理,我会用php函数更新我的真实帖子,你可以看看。。。
$excell = $_FILES["file"]["name"];
            $uploadedfile = $_FILES['file']['tmp_name'];
            if ($excell) {
                $filename = stripslashes($_FILES['file']['name']);
                $extension = $this->getExtension($filename);
                $extension = strtolower($extension);
                if ($extension == ("xlsx" || "xls")) {
                    $newname = $this->Conf->root_dir."/uploads/".Generate::string(5).".$extension";
                    $this->Session->new_file = $newname;
                    move_uploaded_file($uploadedfile, $newname);
                    echo true;
                } else {
                    echo ' It is not Excell ';
                }
            } else {
                echo ' error on upload ';
            }
set_time_limit(0);
        ob_implicit_flush(true);
        ob_end_flush();
        $xlsx = @(new SimpleXLSX($this->Session->new_file));
        $data = $xlsx->rows();
        $totalitems = count($data);
        $lastkey = $totalitems - 1;
        $current = 0;
        foreach ($data as $key => $val) {
            $current++;
            if ($key == 0 || $key == $lastkey) continue;
            // here I`m inserting in tho database
            sleep(1);
            $response = array(
                'loaded' => $current,
                'total' => $totalitems
            );
            echo json_encode($response);
        }

        sleep(1);
        unlink($this->Session->new_file);
        unset($this->Session->new_file);
        $response = array(
            'loaded' => $totalitems,
            'total' => $totalitems
        );
        echo json_encode($response);