laravel pdf file download from ajax request (laravel 5) laravel pdf file download from ajax request (laravel 5) ajax ajax

laravel pdf file download from ajax request (laravel 5)


What I have done is, written two separate route one to verify and one to download.On success of one ajax I have triggered window.open(downloadUrl,'_blank') to download in separete window.It is not the way asked but it prevents any upcoming errors as verify url will sort that

$.ajax({            url: verifyUrl,              type: 'get',            cache: false,            data: null,            error: function (err){$('#ajax_loader_div').hide();},            success: function(response) {                console.log(response);                $('#ajax_loader_div').hide();                if (response.status == 'success')                 {                    window.open(downloadUrl,'_blank');                }else if(response.status == 'error')                 {                    //show error                }            }        });


for that you need to set the header with response object. Please see the below code.

    $headers = array(                  'Content-Type'=> 'application/pdf'                );$file_path = $request->input('file_path');   //TODO: you have to split the file name from url  return Response::download($file_path, '<filename>', $headers);

I hope this code will help you


return Response::download($file_path, '<filename>', $headers);

It's return response, not download file!