2016-04-29 2 views
0

jQueryコードが編集関数に応答し、その後にloademployees関数がトリガーされ、編集された値でテーブルが再度ロードされますが、問題は、それは$ .when()の中でloademployees関数を起動しません。わかりやすくするために私のコードを見てみてください:

$(function(){ 
$('#editEmployeeForm').submit(function(e){ 
    $.when(
     $.ajax({ 
      type: 'POST', 
      url: "<?php echo site_url('tms/updateEmployee');?>", 
      data: $(this).serialize(), 
      success: function(response){ 
       console.log(response); 
      }, 
     }), 
     $.ajax({ 
      type: 'POST', 
      url: "<?php echo site_url('tms/updatePersonalData');?>", 
      data: $(this).serialize(), 
      success: function(response){ 
       console.log(response); 
      }, 
     }), 
     $.ajax({ 
      type: 'POST', 
      url: "<?php echo site_url('tms/updateGovernment');?>", 
      data: $(this).serialize(), 
      success: function(response){ 
       console.log(response); 
      }, 
     }), 
     $.ajax({ 
      type: 'POST', 
      url: "<?php echo site_url('tms/updateRequirements');?>", 
      data: $(this).serialize(), 
      success: function(response){ 
       console.log(response); 
      }, 
     }), 
     $.ajax({ 
      type: 'POST', 
      url: "<?php echo site_url('tms/updateContacts');?>", 
      data: $(this).serialize(), 
      success: function(response){ 
       console.log(response); 
      }, 
     })); 
     $('#modalEditEmployees').modal('hide'); 
     $('#btnloadEmployees').trigger(e.type); 
    }); 
}); 

、ここでは、トリガさせる機能である:

$('#btnloadEmployees').click(function(e){ 
var dept = $('#cmbdept').val(); 
if(dept == "SEWING") 
{ 
    var section = $('#cmbsection').val(); 
    var line = $('#cmbline').val(); 
    var formData = {dSection:section,dLine:line,dept:dept}; 
} 
else 
{ 
    var formData = {dept:dept}; 
} 
$.ajax({ 
    type: 'POST', 
    url: "<?php echo site_url('tms/loadEmployees');?>", 
    data: formData, 
    success: function(response){ 
     console.log(response); 
     $('#tblEmployees tbody').empty(); 
     $('#tblEmployees tbody').append(response); 
    }, 
}); 
}); 

答えて

1

https://api.jquery.com/jquery.when/を参照して、$.whenの構文は

$.when($.ajax(".."), $.ajax(".."), $.ajax("..")).done(function(){ 
    $('#modalEditEmployees').modal('hide'); 
    $('#btnloadEmployees').trigger(e.type); 
}); 
ようにする必要があります

となります。フォームのデフォルトの送信動作を防止するには、事前にe.preventDefault();を入力する必要があります。

+0

私は試しましたが、動作していません.... – SilverRay

関連する問題