And you don't see anything in the console ?
POST onSuccess getting response
Hi, I'm wondering is there a way to get the response data when using onSuccess. Because I can't see data anywhere in the response. This is how I have it set up
// Vue
form.post("/api/book/process", {
onSuccess: (resp) => {
console.log(resp);
}
});
// Controller
return redirect('/book/confirm')->with([
'verificationCode' => '2ef8ec654c'
]);
Well you either have a Inertia response, but with no response body, which is what your redirect was already doing.
Or you want to send data back, but then loose the goodies from the Inertia's form helper, as outlined on Inertia docs: https://inertiajs.com/forms#xhr-fetch-submissions
As a middle ground, what you can try is:
1. js initiate request:
form.post("/api/book/process");
2. first endpoint return a redirect and flash the data to the session
return redirect('/book/confirm')->with(['verificationCode' => '2ef8ec654c']);
3. The controller handling the redirected page, send the verificationCode from the session as a prop:
class BookController extends Controller {
public function index()
{
// reflash to restore the flashed content in session
// in case the user reloads this page
session()->reflash();
return Inertia::render('Index', [
'verificationCode' => session('verificationCode'),
]);
}
}
Then you can do something with the verification code on the client side.
This is not the same thing you were expecting (redirect response with a response body) but it is good compromise, in my opinion.
Please or to participate in this conversation.