Search code examples
jqueryform

jquery form when server failed


I using jquery form plugin from malsup http://jquery.malsup.com/form/

In the http://jquery.malsup.com/form/#getting-started example, how do I modify the code to return error message when server failed, eg return server code 500?


Solution

  • When you call ajaxForm you can pass it an options parameter like that for $.ajax

    So set the error option to a callback function like

    $('#myFormId').ajaxForm(
        {
            success: function(){
                alert("No error!");
            },
            error: function(){
                alert("An error has occured");
            }
        }
    );