douyi1855 2014-04-16 07:48
浏览 40

jquery请求不止一次运行

I have this code to make a request to a file that process some xls files ( with phpexcel library ) :

$("#applyCalls").click(function(){
    $.get("admin/processCalls.php");
});

the processCalls.php looks like this:

include '../phpexcel2/Classes/PHPExcel.php';
include '../phpexcel2/Classes/PHPExcel/IOFactory.php';
date_default_timezone_set('Europe/Bucharest');

$fisierInbound = "inbound.xls";
$fisierOutbound = "outbound.xls";

callsInbound();

function callsInbound() {

        global $fisierInbound;
        global $current;

        global $con;

        $identify = PHPExcel_IOFactory::identify('daily/' . $fisierInbound);
        $objReader = PHPExcel_IOFactory::createReader($identify);
        $objReader->setReadDataOnly(true);
        $objPHPExcel = $objReader->load('daily/' . $fisierInbound);
        $worksheet = $objPHPExcel->setActiveSheetIndex(0);

        $query = mysqli_query($con, "SELECT * FROM users WHERE tip_user='agent' AND NOT (departament='online')");

        while($usr = mysqli_fetch_array($query)) {
                        $data[] = $usr;
        }

        $worksheetTitle     = $worksheet->getTitle();
        $highestRow         = $worksheet->getHighestRow(); // e.g. 10
        $highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
        $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
        $dataCalls = $worksheet->getCellByColumnAndRow(2, 2)->getValue();
        $dataSubstr = substr($dataCalls, 53);
        echo $dataSubstr;
        foreach ($data as $db) {

            for ($row = 6; $row <= $highestRow; ++ $row) {

                $marca      = $worksheet->getCellByColumnAndRow(3, $row)->getValue();
                $nr         = $worksheet->getCellByColumnAndRow(4, $row)->getValue();

                if($db['marca'] == $marca) {
                    mysqli_query($con, "INSERT INTO dailycalls(data, nr, departament, oras, tip, id_user)
                                        VALUES('$dataSubstr', '$nr', '" . $db['departament'] . "', '" . $db['oras'] . "', 'inbound', '" . $db['id'] . "')");
                }
            }
        }
}

The thing is that I get "No data receive Error code: ERR_EMPTY_RESPONSE" (chrome) from processCalls, so the ajax request fails. As it fails I think it is running the file more than once, because I get more results than I need in the db. If I run the file manually I get the results I need. ( side note: the processCalls.php's query runs despite the error I get ). I hope that makes sense.

Thanks!

  • 写回答

3条回答 默认 最新

  • dongwai4434 2014-04-16 07:56
    关注

    Check if the click function is getting binded more than once.

    If the click function is binded more than once the function will be called multiple times.

    $("#applyCalls").off('click', callServer).on('click', callServer);
    
    var callServer = function(){
        $.get("admin/processCalls.php");
    };
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图