Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery表单插件-处理错误回调_Jquery_Ajax_Validation_Callback - Fatal编程技术网

Jquery表单插件-处理错误回调

Jquery表单插件-处理错误回调,jquery,ajax,validation,callback,Jquery,Ajax,Validation,Callback,我正在使用一个jQuery表单插件,它工作得很好。一切都很简单,运作良好。但是现在我想添加一个验证并处理一个错误回调。。而且别无选择!!可能的选择包括: target: '#output1', // target element(s) to be updated with server response beforeSubmit: showRequest, // pre-submit callback success: showRes

我正在使用一个jQuery表单插件,它工作得很好。一切都很简单,运作良好。但是现在我想添加一个验证并处理一个错误回调。。而且别无选择!!可能的选择包括:

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 
所以我不知道我的表格是否有效。现在我想我应该使用JSON,并在我的success函数中添加如下内容:

例如,电子邮件验证:

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

这是一个好的解决方案吗?我希望能够以一种更简单的方式实现这一点。

在提交前的
回调中进行验证。返回
false
以阻止发送表单


EDIT:jQuery表单有一个验证示例-

在提交前的
回调中验证。返回
false
以阻止发送表单


编辑:jQuery表单有一个验证示例-

我想在服务器端验证表单,但您的示例验证在jQuery(即客户端)中。数据对象是从.java控制器返回的JSON对象。所以data.email!=null检查电子邮件字段是否存在验证错误,以及是否存在错误消息(例如:电子邮件不得为空)。我希望在服务器端验证我的表单,但您的示例验证在jQuery(即客户端)中。数据对象是从.java控制器返回的JSON对象。所以data.email!=null检查电子邮件字段是否存在验证错误,以及是否存在错误消息(例如:电子邮件不得为空)