我正在尝试返回要由客户端下载的文件,但是我注意到我在控制器中作为返回值放置的任何内容都不会返回给客户端。
这是代码:
我的控制器中的代码,我删除了不必要的行
public function post_test()
{
if(Input::get('receive_email'))
{
$pdf = new Fpdf('P', 'pt', array(1240, 1754));
$pdf->AddPage();
$generated_pdf = $pdf->Output("", "s");
$body = View::make('test.email_collision')->with($data)->render();
$message->body($body);
$message->attach(
$generated_pdf,
Sentry::user()->metadata['first_name'] . '_' . Sentry::user()->metadata['last_name'] . '.pdf',
'application/pdf');
$message->html(true);
$message->send();
if(Message::was_sent())
{
// HERE I want to actually return the file to be downloaded
// return Response::download($pdf->Output("", "i");
// return $pdf->Output("", "i");
} else {
$errors = new Laravel\Messages();
$errors->add('errors', __('test.error_email_not_sent'));
return Redirect::back()
->with_errors($errors->messages['errors']);
}
}
// Trying to not return anything
// return View::make('collide');
}
我的 JS 文件中执行 POST 的代码
$("#gEmail").bind('touchstart click', function() {
$.ajax({
url: document.URL,
type: 'POST',
data: {
receive_email: "1"
}
})
.fail(function(error) {
console.error(error);
});
uiComplete.hide();
init();
});