Javascript jQuery在生成excel报告时显示加载无ajax
我有一个表单,它有一个日期从和日期选择器,然后是一个生成按钮,单击生成按钮,一个excel文件将被输出。问题:如果我不使用ajax,而是:Javascript jQuery在生成excel报告时显示加载无ajax,javascript,jquery,html,css,loading,Javascript,Jquery,Html,Css,Loading,我有一个表单,它有一个日期从和日期选择器,然后是一个生成按钮,单击生成按钮,一个excel文件将被输出。问题:如果我不使用ajax,而是: $("#btnReport1").click(function() { var page = 'export-report1?from='+$("#fromDateAll").val()+'&to='+$("#toDateAll").val(); return window.location = page; }); 我的路线呢 Ro
$("#btnReport1").click(function() {
var page = 'export-report1?from='+$("#fromDateAll").val()+'&to='+$("#toDateAll").val();
return window.location = page;
});
我的路线呢
Route::get('export-report1', 'ReportController@exportReport1');
作用
public function exportReport1()
{
$from = Input::get('from');
$to = Input::get('to');
$query = "SELECT id, phone FROM qcv.forms WHERE calldatetime >= '$from' AND calldatetime <= '$to' ORDER BY id ASC ;";
// $query = "SELECT a.id as form_id, a.phone, b.metrics_id, b.response, c.metrics_name, c.description, c.question
// FROM forms a
// INNER JOIN forms_responses b ON a.id = b.form_id
// INNER JOIN metrics c ON c.id = b.metrics_id LIMIT 10";
$phone = DB::connection('mysql')->select($query);
if(!empty($phone))
{
Excel::create('Laravel Excel', function($excel) use ($phone) {
return $excel->sheet('Excel sheet', function($sheet) use ($phone) {
$sheet->setOrientation('landscape');
$sheet->cell('A9', 'KEY QUALITY METRICS');
$sheet->cell('B9', 'DESCRIPTIONS');
$sheet->cell('C9', 'ASSESSMENT QUESTION');
$sheet->cells('A9:C9', function($cells) {
$cells->setFontWeight('bold');
$cells->setFontColor('#DF013A');
});
$metrics = Metric::all();
$metric_start = 10;
$start = "D";
$count = 10;
foreach ($phone as $key => $value2) // Populate Phone Numbers Horizontally
{
$sheet->cell($start.'9', $value2->phone);
// This will fill the responses for each number
foreach ($metrics as $key => $value)
{
$responses = FormResponses::where('form_id', '=', $value2->id)->where('metrics_id', '=', $value->id)->get();
$sheet->cell($start.$count, $responses[0]->response);
$sheet->cell('C'.$count, $value->question);
$sheet->cell('B'.$count, $value->description);
$sheet->cell('A'.$count, $value->metrics_name);
$count++;
}
$start++;
$count = 10;
}
});
})->export('xls');
}
else
{
return "No records found.";
}
}
公共函数exportReport1()
{
$from=Input::get('from');
$to=Input::get('to');
$query="选择id,phone FROM qcv.forms,其中calldatetime>='$FROM'和calldatetime您将需要使用AJAX执行此操作。这是最干净的方法。@Shreyas不可以。除非您添加一些技巧,例如制作iframe并在其中传递url,否则我不想这样做。为什么不使用该url打开一个新选项卡?@Shreyas不合适。我需要该页面显示一些加载微调器,让用户知道数据仍在处理中。我想,在他们不知道发生了什么的情况下打开另一个选项卡并不理想。因此,我要做的是显示加载动画,并进行AJAX调用,以生成Excel文件并将其存储在某处。然后,此URL将在AJAX调用中返回。一旦我获得URL,我隐藏加载动画,然后将URL设置为window.location。你需要用AJAX来实现这一点。这是最干净的方法。@shryas-nope。除非你添加一些技巧,如制作iframe并在其中传递URL,否则我不能这样做。为什么不用该URL打开一个新选项卡?@shryas不合适。我需要该页面来显示一些加载微调器让用户知道数据仍在处理中。我想,在他们不知道发生了什么的情况下打开另一个选项卡并不理想。因此,我要做的是,显示加载动画并进行AJAX调用,以生成Excel文件并将其存储到某个位置。然后,此URL将在AJAX调用中返回。一旦我获得URL,我隐藏加载动画,然后将URL设置为window.location。