jquery form plugin, no error handling

前端 未结 5 2138
再見小時候
再見小時候 2020-12-24 14:26

It seems that there are no error handling facility in the Jquery.Form plugin, which is very frustrating. Even though the documentation says we can use the $.ajax options, I

5条回答
  •  太阳男子
    2020-12-24 14:59

    For anybody still needing this, this is a way of getting it to work

    function submitForm()
    {
        var isSuccess   = false,
            options = {
                url         : "posturl.php",
                type        : 'POST',
                dataType    : 'json',
                success:function(msg) {
                    //set the variable to true
                    isSuccess = true;
    
                    //do whatever
                },
                complete: function () {
                    if (isSuccess === false) {
                        //throw the error message
                    }
                }
            };
    
        //Ajax submit the form
        $('#your_form').ajaxSubmit(options);
    
        // always return false to prevent standard browser submit and page navigation
        return false;
     }
    

提交回复
热议问题