代码之家  ›  专栏  ›  技术社区  ›  Kung Fu Ninja

jquery提交问题

  •  0
  • Kung Fu Ninja  · 技术社区  · 16 年前

    我在以下方面有点小麻烦:

    <script>
    $(document).ready(function() {
    $('#sform').validate({
    rules: { firstName: {required:true},
             lastName:  {required:true},
             emailAddress:  {required:true, email:true}
    },
    messages: { firstName: '<br/><span style="color:red;">Please enter your first name!</span>',
                lastName : '<br/><span style="color:red;">Please enter your last name!</span>',
                emailAddress: '<br/><span style="color:red;">Please enter a valid email address!</span>'
    },
       submitHandler: function(form){
       var options = { 
                    beforeSubmit:  showRequest,
                    success: showResponse,
                    type: 'post',
                    url:'sendSurvey.cfm'
                    };
        $(this).ajaxSubmit(options);
        return false;   
       }
     });
    function showRequest(formData, jqForm, options) { 
     $('#formSub').html('We really appreciate your feedback!');
    var queryString = $.param(formData); 
     alert('About to submit: \n\n' + queryString); 
      return true; 
     }
    function showResponse(responseText, statusText) {
      alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
           '\n\nThe output div should have already been updated with the responseText.'); 
     }
     });
     </script>
    

    问题是没有正在过帐的表单数据。$.param(formData)为空。怎么办?谢谢

    1 回复  |  直到 16 年前
        1
  •  1
  •   Nick Craver    16 年前

    你需要提交 <form> ,所以你的内容有点不对劲,而不是这样:

    $(this).ajaxSubmit(options);
    

    你需要这个:

    $(form).ajaxSubmit(options);
    

    你在哪里打电话 this submitHandler , 这 引用验证对象本身,而不是 <表格> form 传入的DOM元素引用。