开发者

Jquery Form Plugin - handling error callback

开发者 https://www.devze.com 2023-03-10 00:32 出处:网络
I\'m using 开发者_C百科a jQuery form plugin link and it works great. everything is simple and works fine. But now I want to add a validation and handle a error callback.. and there is no option!! Poss

I'm using 开发者_C百科a jQuery form plugin link and it works great. everything is simple and works fine. But now I want to add a validation and handle a error callback.. and there is no option!! Possible options are :

target:        '#output1',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
    success:       showResponse  // post-submit callback 

    // other available options: 
    //url:       url         // override for form's 'action' attribute 
    //type:      type        // 'get' or 'post', override for form's 'method' attribute 
    //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
    //clearForm: true        // clear all form fields after successful submit 
    //resetForm: true        // reset the form after successful submit 

    // $.ajax options can be used here too, for example: 
    //timeout:   3000 

So I don't know if my form was valid. Now I'm thinking I should use JSON and put something like this in my success function :

for example email validation:

function finish(data) (
  if (data.email != null) $("#emailErrorDiv").html(data.email);
  .......
  if (data.success != null) $("#successDiv").html(data.success);
)

Is it a good solution? I hope it is possible to achieve this in a simpler way.


Validate in the beforeSubmit callback. Return false to block sending the form.

EDIT: jQuery Form has an example with validation - jQuery Form Validation

0

精彩评论

暂无评论...
验证码 换一张
取 消