Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

All Inertia requests must receive a valid Inertia response, however a plain JSON response was received [closed]

i am trying to understand and resolve this InertiaJs error without success i hope i can get some help here.  valid Inertia response

like image 675
Ismael Kourouma Avatar asked Dec 20 '25 13:12

Ismael Kourouma


2 Answers

Late to the party replying, but in your controller:

return Redirect::back()->with([
  'data' => 'Something you want to pass to front-end',
])

Then on the front end:

this.form.post(route(...), {
  onSuccess: (res) => {
    this.form.data = res.props.data
  },
})

this.form, in my case, is set as the following in data(){ ...

form: this.$inertia.form({
  _method: 'PUT',
}),

(Adjust to your requirements)

data exists within the props response after a successful form update via Inertia. Helped me when I was digging around for an answer anyway.

This answer helped me get here, although not quite the same. Hope my answer helps!

like image 105
Daze Avatar answered Dec 23 '25 04:12

Daze


Maybe your are using this.$inertia, it waits for Inertia response;

this.$inertia.get(route('example'))
  .then(res => {
     console.log(res)
  })

Please use axios instead

axios.get(route('example'))
  .then(res => {
     console.log(res)
  })
like image 33
Manuel Eduardo Romero Avatar answered Dec 23 '25 03:12

Manuel Eduardo Romero