English 中文(简体)
JQuery 验证方法 提交联合材料
原标题:JQuery validate() method plugin with JS submit

我有以下法典:

<a href="#" onclick="submit_form( http://allstateagents.contextoptional.com//create_lead ); return false;"><img alt="Btn_requestaquote" src="http://a0.allstateagents.contextoptional.com/images/btn_requestAquote.png?1317752211"></a>

相当于:

function submit_form(posturl) {
    $.ajax({
      url:  /create_lead ,
      data: {
         lead_gen[promotion_id] : $( #lead_gen_promotion_id ).val(),
         lead_gen[name] : $( #lead_gen_name ).val(),
         lead_gen[email] : $( #lead_gen_email ).val(),
      },
      type:  POST ,
      dataType:  json ,
      success: function(data) {
        console.log(data)
         $( #content ).html(data.html);
      }
    });

我称之为验证和我的形式、技巧验证,直截了当。 我知道,验证工作正在进行,因为我利用一项活动来要求验证工作。

$(document).ready(function(){
    $("#lead_gen_email").validate();
    console.log("testing validate")


    $("#lead_gen_email").validate({
       onkeyup: true
    })

  });
   }

我做了一些错误? 我如何确定这一点?

最佳回答

这是因为你把一个jax员额留到Click。 它向审定稿开火,无<>。 类似情况

$( #yourlink ).click(function(e){
 if (aVariableThatIndicatesPresenceOfErrors) {
  e.preventDefault()
 } else {
  submit_form(posturl)
 }

})

当然,这一变量必须有所作为。 也许一位带有错误信息类别的选择人?

var hasError = $( div.error ).length;

不能确定验证金刚金是否具有背书方法,这可能会否定这一切。

问题回答

您需要实际利用提交活动的表格,以自动确认。 你的代码只是通过ja子(ajax w)向服务器派驻人员,甚至验证任何东西。

您可以使用以下法典:

function submit_form(posturl) {
if ($("#targetFormId").valid()) {
$.ajax({
  url:  /create_lead ,
  data: {
     lead_gen[promotion_id] : $( #lead_gen_promotion_id ).val(),
     lead_gen[name] : $( #lead_gen_name ).val(),
     lead_gen[email] : $( #lead_gen_email ).val(),
  },
  type:  POST ,
  dataType:  json ,
  success: function(data) {
    console.log(data)
     $( #content ).html(data.html);
  }
}
});

将“目标”改为“目标”。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签