Level 73
Using ajax to download a file seems a bit strange to me, however it seems that someone managed here
https://www.codeproject.com/Articles/5308865/Download-File-via-Ajax
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm attempting to have laravel download a file during an ajax call. Everything is running smoothly with no errors, however no file is downloaded on the user's side. The check on the if statement is returning as true, so the file is there.
$file = 'json/fs_'.strtolower($entry->country).'.json';
if(Storage::disk('public')->exists($file)){
Storage::disk('public')->delete($file);
Storage::disk('public')->put($file, json_encode($entry));
}
}
Storage::disk('public')->download($file);
return response()->json(['success' => $country]);
Please or to participate in this conversation.