Basically, what I'm trying to achieve here is quite complicated.
I want to be able to use one Ajax function throughout my website to control the updating of information. Basically, a universal update script which'll activate on a form submission.
However, the issue I'm having is, I also want specific forms to also perform another function on the ajax success callback.
So, for example, I click update on personal information, that'll then update the database and on the success callback, it'll also call another function which I set in the Laravel response back to the Ajax.
The function in the success callback will then update the personal information section with the new data.
Please see current code below:
Laravel
return ['success' => true, 'function_name' => 'updtPersonal', 'msg' => '<i class="fa fa-check fa-fw"></i> You successfully updated your personal statement', 'data' => $request];
Ajax
$('.ajaxUpdt').on('submit',function(e){
var action = $(this).attr('action');
var method = $(this).attr('method');
$.ajaxSetup({
header:$('meta[name="_token"]').attr('content')
})
e.preventDefault(e);
$.ajax({
type: method,
url: action,
data:$(this).serialize(),
dataType: 'json',
success: function(data){
success(data.msg);
},
error: function(msg){
fail("Fail");
}
});
});
Any help would as always, be much appreciated!
Cheers
Matt
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire