1

有没有办法选择特定的形式进行序列化?我的 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);
                }
            }
        });
    });
4

1 回答 1

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,并防止默认...

$('#form').submit(function(e) {
 e.preventDefault();
 var data = $(this).serialize();
 $.ajax({
    type: "POST",
     url: your url,
    data: data,
    success: function(){ your functions}
  });
});
于 2013-06-05T20:17:15.137 回答