I have an ajax POST request being sent to a laravel controller, this works fine. I do some work in the controller and I get a string that can vary in size from a few hundred kilobytes to hundreds of megabytes.
I want to download this string as a file and I've been trying various methods, but the problem is whenever I use return to pass the string to a different controller or a different page it returns the output to the ajax success instead. I've tried removing the success, but it still does not work.
/*POST request*/
$.ajax({
type:"post",
url:"{{ URL::route('sshDownload') }}",
data: {
id:id
file:file,
status:"logfile"
},
success:function(data){
console.log(data);
console.log("SUCCESS");
}
});
In my sshDownload
controller I'm trying to do something like this:
return Response::make($output, '200', array(
'Content-Type' => 'text/plain',
'Content-Disposition' => 'attachment; filename="file.log'
));
and I've even tried:
return Redirect::route('sshDownloadName')->with($output);
but in the end, anytime I use return it sends the data back to to the front end ajax.
How can I download the string directly from PHP instead of sending it to ajax?