Ajax from

With Laraloop you can enable ajax form submissions for any forms. Using code generator all forms use already ajax form and you can disable if you wish.

For each form that you want to use ajax submission just add attribute data-ajax. Example:

<form action="" method="post" data-ajax>
  // form elements
</form>

Callback on success

You can add a callback function that will be executed on success using data-callback=callbackFunctionName. Example:

<form action="" method="post" data-callback="onSuccess" data-ajax>
  // form elements
</form>
function onSuccess(message) {
  // callback function
}

If you need just to reload page after successfully ajax submission you can add attribute data-callback="reload". Example:

<form action="" method="post" data-callback="reload" data-ajax>
  // form elements
</form>

Another way is to listen on success event using:

$(document).on('loop:ajaxform.success', function(event) {
  // event.responseText
  // event.statusText
  // event.xhr
  // event.form
})

Or on error event:

$(document).on('loop:ajaxform.error', function(event) {
  // event.xhr
  // event.status
  // event.error
})

You can see an example of usage in user settings view me/settings.blade.php that update to navigation user name and username after updating via ajax.

$(document).on('loop:ajaxform.success', function (response) {
   if(response.responseText.payload) {
       $('.btn-account').html($.templates("#templateButtonAccount").render(response.responseText.payload));
   }
})

The server return in payload whole user data:

  return $this->respondWithSuccess([
    'message' => 'Profile updated successfully.',
    'payload' => new UserResource($user)
  ]);