I have the same issue as well.
Laravel Jetstream Inertia returing data from axios request
I have a contact form within a modal and I want to send that form using a regular axios/ajax request.
this.form.post(route('contact-form.submit'), {
preserveScroll: true
}).then(response => {
if (! this.form.hasErrors()) {
this.sendingMessage = false
}
console.log(response.data);
})
On the server-side I was trying to return some data(success message) back, using the regular Laravel response method:
return response()->json(['key' => 'some value']);
but then I got a white modal that states at the top: "All Inertia.js requests must receive a valid Inertia.js response, however a return plain JSON response was received."
I looked then on some other vendor methods that does some similar ajax updates, and in those responses, it something like this:
return back(303)->with('key', 'some value');
After few failed tries, I tried with a regular axios request, but now I got the CSRF missmatch token, but in bootstrap.js file, the token it's added to the axios header by default. And also inertia uses axios under the hood, so why in this case works?
So i just want a regular ajax request using inertia that returns back some data from the server but without redirect to another page.
Please or to participate in this conversation.