Last active
March 2, 2017 04:34
-
-
Save graciano/4c41cc3c139ae5c7db70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sendAjaxFormLaravel = function(form, callbacks){ | |
var formAction = form.attr('action'); | |
var formMethod = form.attr('method'); | |
var formData; | |
if(formMethod.toLowerCase() == 'post'){ | |
formData = form.serializeArray(); | |
$.ajaxSetup({ | |
headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') } | |
}); | |
} | |
else | |
formData = form.serialize(); | |
$.ajax({ | |
type: formMethod, | |
url: formAction, | |
data: formData, | |
cache: false, | |
success: (callbacks && callbacks.hasOwnProperty('success'))? callbacks.success : function(data) { | |
console.log(data); | |
console.log("success"); | |
}, | |
error: (callbacks && callbacks.hasOwnProperty('error'))? callbacks.error : function(data) { | |
console.log(data); | |
console.log("error"); | |
} | |
},"json"); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment