Php jquery请求多次运行
我使用以下代码请求处理某些xls文件的文件(使用phpexcel库): processCalls.php如下所示:Php jquery请求多次运行,php,jquery,ajax,request,Php,Jquery,Ajax,Request,我使用以下代码请求处理某些xls文件的文件(使用phpexcel库): processCalls.php如下所示: include '../phpexcel2/Classes/PHPExcel.php'; include '../phpexcel2/Classes/PHPExcel/IOFactory.php'; date_default_timezone_set('Europe/Bucharest'); $fisierInbound = "inbound.xls"; $fisierOutbo
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'] . "')");
}
}
}
}
包括“../phpexcel2/Classes/PHPExcel.php”;
包括“../phpexcel2/Classes/PHPExcel/IOFactory.php”;
日期默认时区设置(“欧洲/布加勒斯特”);
$fisierInbound=“inbound.xls”;
$fisierOutbound=“outbound.xls”;
callsInbound();
函数callsInbound(){
全球500万美元;
全球流动美元;
全球$con;
$identify=PHPExcel_IOFactory::identify('daily/'。$fisierInbound);
$objReader=PHPExcel\u IOFactory::createReader($identify);
$objReader->setReadDataOnly(true);
$objPHPExcel=$objReader->load('daily/'。$fisierInbound);
$worksheet=$objPHPExcel->setActiveSheetIndex(0);
$query=mysqli\u query($con,“从用户中选择*,其中提示用户为代理,而非(department='online')”;
而($usr=mysqli\u fetch\u数组($query)){
$data[]=$usr;
}
$worksheetTitle=$worksheet->getTitle();
$highestRow=$worksheet->getHighestRow();//例如10
$highestColumn=$worksheet->getHighestColumn();//例如'F'
$highestColumnIndex=PHPExcel_单元::columnIndexFromString($highestColumn);
$dataCalls=$worksheet->getCellByColumnRow(2,2)->getValue();
$dataSubstr=substr($dataCalls,53);
echo$dataSubstr;
foreach($db形式的数据){
对于($row=6;$row GetCellByColumnRow(3,$row)->getValue();
$nr=$worksheet->getCellByColumnRow(4,$row)->getValue();
如果($db['marca']=$marca){
mysqli_查询($con,“插入到DailCalls中(数据、nr、部门、oras、tip、id_用户)
值(“$dataSubstr”、“$nr”、“$db['departments']”、“$db['oras']”、“inbound”、“$db['id']”);
}
}
}
}
问题是,我从processCalls中获得了“No data receive Error code:ERR_EMPTY_RESPONSE”(chrome),因此ajax请求失败。由于失败,我认为它不止一次地运行该文件,因为我在数据库中得到的结果比我需要的多。如果我手动运行该文件,我会得到我需要的结果。(旁注:processCalls.php的查询会运行,尽管我遇到了错误)
谢谢!检查单击功能是否被多次绑定 如果click函数绑定多次,则该函数将被多次调用
$("#applyCalls").off('click', callServer).on('click', callServer);
var callServer = function(){
$.get("admin/processCalls.php");
};
尝试使用
stopPropagation()
函数
另外,由于PHP不返回任何内容,因此应该使用POST
而不是GET
要了解POST
和GET
之间的区别,请查看
你试过这个吗
$("#applyCalls").unbind("click").click(function(){$.get("admin/processCalls.php");});
在控制台中,我看到一个请求,它在3-4秒后失败。关闭。打开似乎是现在的方法
$("#applyCalls").click(function(event){
event.stopPropagation()
$.post("admin/processCalls.php");
});
$("#applyCalls").unbind("click").click(function(){$.get("admin/processCalls.php");});