Laravel - Jquery Event preventDefault is not allowing entering the records in the database?

Asked

Viewed 66 times

-1

I used the following code JQuery to avoid page reloading when entering a record in the bank. actually stopped reloading, but is not allowing to record the records in the database.

$( "#btnAtividades" ).click(function( event ) {
      event.preventDefault();
});

I was told that I have to put something else after the event, but no one explains to me exactly what I found some examples but it was in pure PHP and I’m using Laravel.

1 answer

0

The preventDefault causes the default behavior of the current event to be blocked, in your case the event click, that is, if you block the event click the button that makes the Submit from your form to Laravel, this form is never sent.

According to the MDN, Event.preventDefault():

Cancel the event if cancellable, without stopping the spread of the event.

https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault

If you want to enter this data in Laravel without the page being reloaded, you can send via ajax with a method POST and make your controller return a successful http Response (200) or error if it occurs.

https://api.jquery.com/jquery.ajax/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.