<tfoot id='2yxIP'></tfoot><legend id='2yxIP'><style id='2yxIP'><dir id='2yxIP'><q id='2yxIP'></q></dir></style></legend>
    1. <small id='2yxIP'></small><noframes id='2yxIP'>

    2. <i id='2yxIP'><tr id='2yxIP'><dt id='2yxIP'><q id='2yxIP'><span id='2yxIP'><b id='2yxIP'><form id='2yxIP'><ins id='2yxIP'></ins><ul id='2yxIP'></ul><sub id='2yxIP'></sub></form><legend id='2yxIP'></legend><bdo id='2yxIP'><pre id='2yxIP'><center id='2yxIP'></center></pre></bdo></b><th id='2yxIP'></th></span></q></dt></tr></i><div id='2yxIP'><tfoot id='2yxIP'></tfoot><dl id='2yxIP'><fieldset id='2yxIP'></fieldset></dl></div>

          <bdo id='2yxIP'></bdo><ul id='2yxIP'></ul>

        struts2 jquery ajax 和客户端验证不能一起工作

        struts2 jquery ajax and client side validatio not working toghether(struts2 jquery ajax 和客户端验证不能一起工作)
          <tbody id='SVSFb'></tbody>

              <bdo id='SVSFb'></bdo><ul id='SVSFb'></ul>
              <i id='SVSFb'><tr id='SVSFb'><dt id='SVSFb'><q id='SVSFb'><span id='SVSFb'><b id='SVSFb'><form id='SVSFb'><ins id='SVSFb'></ins><ul id='SVSFb'></ul><sub id='SVSFb'></sub></form><legend id='SVSFb'></legend><bdo id='SVSFb'><pre id='SVSFb'><center id='SVSFb'></center></pre></bdo></b><th id='SVSFb'></th></span></q></dt></tr></i><div id='SVSFb'><tfoot id='SVSFb'></tfoot><dl id='SVSFb'><fieldset id='SVSFb'></fieldset></dl></div>
              <tfoot id='SVSFb'></tfoot>

              1. <small id='SVSFb'></small><noframes id='SVSFb'>

                <legend id='SVSFb'><style id='SVSFb'><dir id='SVSFb'><q id='SVSFb'></q></dir></style></legend>
                • 本文介绍了struts2 jquery ajax 和客户端验证不能一起工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用了来自 http://struts.jgeppert.com 的标准代码片段/struts2-jquery-showcase/index.action 和 http://code.google.com/p/struts2-jquery/wiki/Validation.

                  I have used standard code snippet from http://struts.jgeppert.com/struts2-jquery-showcase/index.action and http://code.google.com/p/struts2-jquery/wiki/Validation.

                  但是客户端和 ajax 服务器端验证不能一起工作.

                  But the client side and ajax server side validations are not working together.

                  问题是表单提交不会停止并且即使我们 preventDefault 或执行其他任何操作也会调用操作.

                  The problem is form submission does not stop and action gets called even if we preventDefault or do anything else.

                  <%@ taglib prefix="s" uri="/struts-tags"%>
                  <%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
                  <html>
                    <head>
                      <sj:head jqueryui="true"/>
                  
                    </head>
                    <body>
                          <div id="result">
                              <s:actionerror/>
                              <s:fielderror fieldName="name" value="eroor"></s:fielderror>
                          Submit form bellow.</div>
                  
                          <!-- A List for Global Error Messages -->
                      <ul id="formerrors" class="errorMessage"></ul>
                  
                      <s:form id="formValidateCustom" action="register1.action" namespace="/" theme="simple" cssClass="yform" >
                          <fieldset>
                              <legend>AJAX Form with Validation</legend>
                                  <div class="type-text">
                                      <label for="echo">User: <span id="loginuserError"></span></label>
                                                  <sj:textfield id="name" name="name" />
                                  </div>
                                  <div class="type-text">
                                      <label for="echo">Password: <span id="loginpasswordError"></span></label>
                                          <sj:textfield id="password" name="password" />
                                  </div>
                                  <div class="type-button">
                                          <sj:submit 
                                                  targets="result" 
                                                  button="true" 
                                                  validate="true" 
                                                  validateFunction="customeValidation"
                                                  value="Submit" 
                                                  onBeforeTopics="before"
                                                  timeout="2500" 
                                                  indicator="indicator"
                                          />
                                  </div>
                          </fieldset>
                      </s:form>
                          <script type="text/javascript">
                  
                          function customeValidation(form, errors) {
                  
                                  //List for errors
                  //              alert("in js");
                                  var list = $('#formerrors');
                  
                                  //Handle non field errors 
                                  if (errors.errors) {
                                          $.each(errors.errors, function(index, value) { 
                                                  list.append('<li>'+value+'</li>
                  ');
                                          });
                                  }
                  
                                  //Handle field errors 
                                  if (errors.fieldErrors) {
                                          $.each(errors.fieldErrors, function(index, value) { 
                                                  var elem = $('#'+index);
                                                  if(elem)
                                                  {
                                                          alert(value[0]);
                                                  }
                                          });
                                  }
                          }
                          $.subscribe('before', function(event,data) {
                               var fData = event.originalEvent.formData;
                               alert('About to submit: 
                  
                  ' + fData[0].value + ' to target '+event.originalEvent.options.target+' with timeout '+event.originalEvent.options.timeout );
                               var form = event.originalEvent.form[0]; 
                               if (form.name.value.length  < 2) { 
                                   alert('Please enter a value with min 2 characters');
                  
                                   **// the event does not stop here if we use ajax validation i.e validate = true, if we remove it then this works.**
                                   event.originalEvent.options.submit = false; 
                               } 
                              });
                      </script>
                    </body>
                  </html>
                  

                  如果我们使用 ajax 验证,即在提交按钮中使用 validate = true,则 event.originalEvenet.options.submit = false 不会在此处停止,如果我们将其删除,则此方法有效.**

                  the event.originalEvenet.options.submit = false does not stop here if we use ajax validation i.e validate = true in submit button, if we remove it then this works.**

                  推荐答案

                  嗯,

                  我在这里查看了 struts2 jquery 插件代码 o.validate 调用 struts2 中的验证函数,而 o.options.submit 设置为 false 时不会调用实际操作.

                  I looked into struts2 jquery plugin code here o.validate calls validate function in struts2 while o.options.submit when set to false does not calls the actual action.

                  现在,如果我的客户端验证也应该能够阻止 ajax 验证.

                  Now if my client side validation is should be able to block ajax validation too.

                  但在这里,我无法设置 event.originalEvent.validate = false 因此 ajax 验证将始终发生.

                  But here, I am not able to set event.originalEvent.validate = false hence ajax validation will happen always.

                  需要某种方式来解决这个问题,这是一个原生库,有一个用例,其中客户端验证必须能够撤销服务器端验证并避免网络调用.

                  Need someway to fix this is native library to have a use case, where client side validation must be able to revoke server side validation and avoid network call.

                  params.beforeSubmit = function(formData, form, formoptions) {
                  
                          var orginal = {};
                          orginal.formData = formData;
                          orginal.form = form;
                          orginal.options = formoptions;
                          orginal.options.submit = true;
                  
                          s2j.publishTopic(elem, always, orginal);
                  
                          if (o.onbef) {
                              $.each(o.onbef.split(','), function(i, topic) {
                                  elem.publish(topic, elem, orginal);
                              });
                          }
                  
                          if (o.validate) {
                              orginal.options.submit = s2j.validateForm(form, o);
                              orginal.formvalidate = orginal.options.submit; 
                              if (o.onaftervalidation) {
                                  $.each(o.onaftervalidation.split(','), function(i, topic) { 
                                      elem.publish(topic, elem, orginal);
                                  });
                              }  
                          }
                          if (orginal.options.submit) {
                              s2j.showIndicator(indi);
                              if(!o.datatype || o.datatype !== "json") {
                                  if (o.loadingtext && o.loadingtext !== "false") {
                                      $.each(o.targets.split(','), function(i, target) {
                                          $(s2j.escId(target)).html(o.loadingtext);
                                      });
                                  }
                                  else if (s2j.defaults.loadingText !== null) {
                                      $.each(o.targets.split(','), function(i, target) {
                                          $(s2j.escId(target)).html(s2j.defaults.loadingText);
                                      });
                                  }
                              }
                          }
                          return orginal.options.submit;
                      };
                  
                      params.success = s2j.pubSuc(elem, always, o.onsuc, indi, 'form', o);
                      params.complete = s2j.pubCom(elem, always, o.oncom, o.targets, indi, o);
                      params.error = s2j.pubErr(elem, always, o.onerr, o.errortext, 'html');
                  
                      $.each(o.formids.split(','), function(i, fid) {
                          s2j.log('submit form : ' + fid);
                          $(s2j.escId(fid)).ajaxSubmit(params);
                      });
                  
                      return false;
                  });
                  

                  这篇关于struts2 jquery ajax 和客户端验证不能一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What are valid deviceNames for Chrome emulation testing with Protractor?(使用 Protractor 进行 Chrome 模拟测试的有效设备名称是什么?)
                  Protractor Check if Element Does Not Exist(量角器检查元素是否不存在)
                  Protractor e2e Tests Login Redirection(Protractor e2e 测试登录重定向)
                  Explain about async/ await in Protractor(解释 Protractor 中的 async/await)
                  Protractor browser.wait doesn#39;t wait(量角器 browser.wait 不等待)
                  How to use Protractor with Angular 2?(如何在 Angular 2 中使用量角器?)
                  1. <small id='XQu9R'></small><noframes id='XQu9R'>

                          <bdo id='XQu9R'></bdo><ul id='XQu9R'></ul>
                              <tbody id='XQu9R'></tbody>

                            <legend id='XQu9R'><style id='XQu9R'><dir id='XQu9R'><q id='XQu9R'></q></dir></style></legend><tfoot id='XQu9R'></tfoot>

                            <i id='XQu9R'><tr id='XQu9R'><dt id='XQu9R'><q id='XQu9R'><span id='XQu9R'><b id='XQu9R'><form id='XQu9R'><ins id='XQu9R'></ins><ul id='XQu9R'></ul><sub id='XQu9R'></sub></form><legend id='XQu9R'></legend><bdo id='XQu9R'><pre id='XQu9R'><center id='XQu9R'></center></pre></bdo></b><th id='XQu9R'></th></span></q></dt></tr></i><div id='XQu9R'><tfoot id='XQu9R'></tfoot><dl id='XQu9R'><fieldset id='XQu9R'></fieldset></dl></div>