Jquery序列化选定的表单

时间:2013-06-05 20:10:06

标签: jquery

有没有办法选择要序列化的特定表单?我的CF页面上有多个表单。我想选择一个特定的表单,提交ajax帖子,然后选择第二个表单并提交ajax帖子。

$('.CSubmitSurvey').live('click', function(e) {
        var strCandidateSurveyForm = $('#sendSurveysCandidate').serialize();
        alert (strCandidateSurveyForm);
        IndividualNumber = document.getElementById('sendSatTo2').value;
        companyNumber = document.getElementById('companyID').value;
        surveyNumber = document.getElementById('surveyID').value;
        resendSurvey = document.getElementById('ReSendYN').value;
        RefID = document.getElementById('RefID').value;
        ClientCandidate = document.getElementById('ClientCandidate').value;
        EmailOverride = document.getElementById('EmailOverride').value;
        SendSatEmail = $('input:radio[name=SendSatEmail]:checked').val()
        //alert(SendSatEmail);
        $.ajax({
            type: "POST",
            url: 'actSendSurveys.cfm',
            data:  '<cfoutput>indivNum=' + IndividualNumber + '&board_type=#board_type#&jobid=' + jobid + '&companyid=' + companyNumber + '&resendyn=' + resendSurvey + '&SurveyNumber=' + surveyNumber + '&RefID=' + RefID + '&ClientCandidate=' + ClientCandidate + '&SendSatEmail=' + SendSatEmail + '&EmailOverride=' + EmailOverride</cfoutput>,
            error: function(xhr, textStatus, errorThrown) {
                // show error
                alert(errorThrown);
            },
            success: function(response1, textStatus, jqXHR) {
                //alert('success');
                if (ClientCandidate == 'client'){
                    ColdFusion.Grid.refresh('ClientSurveyGrid',true);
                }
                else {
                    ColdFusion.Grid.refresh('CandSurveyGrid',true);
                }
            }
        });
    });

1 个答案:

答案 0 :(得分:0)

对于所有按钮,只需应用Jquery点击处理程序... 如果按钮不是表单的一部分。

$('#button1').click(function{
var data = $('#form1').serialize();
   $.ajax({
     type: "POST",
     url: your url,
     data: data,
     success: function(){ your functions}
   });
});

    $('#button2').click(function{
    var data = $('#form2').serialize();
   $.ajax({
     type: "POST",
     url: your url,
     data: data,
     success: function(){ your functions}
   });
});

如果按钮是表单的一部分,你可以只提交一个Jquery onsubmit,防止默认...

$('#form').submit(function(e) {
 e.preventDefault();
 var data = $(this).serialize();
 $.ajax({
    type: "POST",
     url: your url,
    data: data,
    success: function(){ your functions}
  });
});