@drewlim7
Hi,
I am new to this forum.
Did you solve your issue?
I had the same issue, especially the empty array after using $.ajaxSetup and I finally found the solution thanks to good luck!
Two things to know:
-
you don't need $.ajaxSetup; as long as you have that "_token" in your formData, it is perfectly fine. It can be either the content attribute of your meta tag or the @csrf of your blade view
-
$.ajax & Laravel ? Forget PATCH, DELETE, PUT and all that stuff; HTTP protocol only knows GET and P(R)OST
So for your ajax call, always stick to type: 'post'.
If you need to call in PATCH or DELETE mode, then pass the "_method" in your formData and Laravel will handle it as a PATCH call.
To check you have everything you need in your formData:
for (var key of formData.entries()) {
console.log(key[0] + ', ' + key[1]);
}
You should see something like in Chrome Console:
_token, YOUR_TOKEN
_method, patch
id, 9
label, Toto
label_kh, Titi
At the end, you ajax call should be:
$.ajax({
url: [your url],
type: 'post',
data: formData,
processData: false,
contentType: false,
success: (object) => {...},
error: (error) => {...},
complete: () => {...}
})
Hope this helps.