Skip to content
Advertisement

Cannot send data to database using Ajax and Laravel

I am trying to insert data to database through Ajax And Laravel. But when I click the submit button, nothing happens at all. I tried to see if the javascript is reachable at the first using “Alert” and yes it is. But the part of $ajax is not reachable at all.

Here is the code:

Html:

JavaScript

Javascript:

JavaScript

for the controller code:

JavaScript

The browser debugging shows this error:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

Advertisement

Answer

Try this one…

First of all set meta tag in your blade file’s html head tag.

JavaScript

Define ROUTES like this

JavaScript

Then change your button type if you are not using FORM to submit the data.

JavaScript

Then add this script.

JavaScript

Now change your controller’s store function.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement