Note that there are some explanatory texts on larger screens.

plurals
  1. POLaravel 3: AJAX POST and return Response::download()?
    text
    copied!<p>I'm trying to return a file to be downloaded by the client however I've noticed that anything I put as a return value in my controller doesn't get returned to the client.</p> <p>Here's the code:</p> <p><strong>Code in my Controller, I've removed unnecessary lines</strong></p> <pre><code>public function post_test() { if(Input::get('receive_email')) { $pdf = new Fpdf('P', 'pt', array(1240, 1754)); $pdf-&gt;AddPage(); $generated_pdf = $pdf-&gt;Output("", "s"); $body = View::make('test.email_collision')-&gt;with($data)-&gt;render(); $message-&gt;body($body); $message-&gt;attach( $generated_pdf, Sentry::user()-&gt;metadata['first_name'] . '_' . Sentry::user()-&gt;metadata['last_name'] . '.pdf', 'application/pdf'); $message-&gt;html(true); $message-&gt;send(); if(Message::was_sent()) { // HERE I want to actually return the file to be downloaded // return Response::download($pdf-&gt;Output("", "i"); // return $pdf-&gt;Output("", "i"); } else { $errors = new Laravel\Messages(); $errors-&gt;add('errors', __('test.error_email_not_sent')); return Redirect::back() -&gt;with_errors($errors-&gt;messages['errors']); } } // Trying to not return anything // return View::make('collide'); } </code></pre> <p><strong>Code in my JS file which does the POST</strong></p> <pre><code> $("#gEmail").bind('touchstart click', function() { $.ajax({ url: document.URL, type: 'POST', data: { receive_email: "1" } }) .fail(function(error) { console.error(error); }); uiComplete.hide(); init(); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload