Why not just serialize the form data?
$.ajax({
...
data: $(this).serialize(),
...
});
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to update some form data using the @update action of a resource controller, but along the way learned that apparently it is not possible to use PUT in an ajax call together with a FormData object, i.e. it will result in an empty request on the server side. source: http://stackoverflow.com/questions/26630923/angularjs-service-file-upload-laravel/26631348#26631348
So in my controller I am simply returning all request data like so:
public function update(Request $request, $id)
{
return Response::json($request->all(), 200);
}
So this doesn't work:
// seems no request data makes it to the server
...
var formData = new FormData(this);
$ajax({
method: PUT,
url: $(this).prop('action'),
data: formData,
processData: false,
contentType: false,
headers: { 'X-CSRF-TOKEN': token },
success: function(data, textStatus, jqXHR) {
console.log(data); // prints out an empty array
}
});
...
Now I found a couple of workarounds. The first one sticking to PUT and instead of FormData using a simple JSON approach:
// this seems to work fine for PUT
$ajax({
method: PUT,
url: $(this).prop('action'),
data: { testData: 'this is a test' },
headers: { 'X-CSRF-TOKEN': token },
success: function(data, textStatus, jqXHR) {
console.log(data); // prints out the data
}
});
I am not really sure why the above does work. I mean, why is this allowed, but the use of FormData isn't???
The other workaround I haven't tried yet, but I guess it will work, is to simply add an additional route before my resource controller:
Route::post(some/route, MyController@update);
However, this seems a little hacky to me, since the @update route already exists. Or is this fine? What is the recommended approach here?
Any advice is much appreciated.
Please or to participate in this conversation.