Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Form Plugin - Callback function for failure?

Tags:

jquery

For the jquery form plugin http://jquery.malsup.com/form/#options-object, I see a success callback, but how do I run code if there is a failure like a network issue?

like image 756
Kyle Avatar asked Apr 14 '26 17:04

Kyle


2 Answers

From the site:

Aside from the options listed below, you can also pass any of the standard $.ajax options to ajaxForm and ajaxSubmit

Presumably that means you could just add an "error" property with the function you'd like to execute upon error.

Looking at the plugin code that seems to be the case:

$.fn.ajaxForm = function(options) {
    ...
    $(this).ajaxSubmit(options);
    ...
}

...

$.fn.ajaxSubmit = function(options) {
    ...
    $.ajax(options);
    ...
}
like image 59
CalebD Avatar answered Apr 16 '26 20:04

CalebD


'error' callback handler should be enabled:

"Note: Aside from the options listed below, you can also pass any of the standard $.ajax options to ajaxForm and ajaxSubmit." (http://jquery.malsup.com/form/#options-object)

like image 38
mamoo Avatar answered Apr 16 '26 18:04

mamoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!