0
我正在從jQuery數據表加載來自mysql數據庫的少量數據。如何使用jQuery數據表使用onChange事件獲取選定的數據?
下面是HTML代碼:
<table id="employee-grid" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
<thead>
<tr>
<th>#</th>
<th>User Id</th>
<th>Address</th>
<th>Package Name</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
</table>
jQuery的數據表和我的AJAX請求的jQuery代碼:
$(document).ready(function() {
var dataTable = $('#employee-grid').DataTable({
"processing": true,
"serverSide": true,
"ajax":{
url :"server_processing.php", // json datasource
type: "post", // method , by default get
error: function(){ // error handling
$(".employee-grid-error").html("");
$("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#employee-grid_processing").css("display","none");
}
}
});
$("#employee-grid").on('change', function() {
var status = $('.changeStatus').val();
alert(status);
$.ajax({
url : "<?php echo SITE_URL . 'toplevel/update-data'; ?>",
data : {
'statusChange' : status
},
type : 'POST',
});
});
});
,但是當我選擇的選項,然後它通過每一次第一個選項值
例如這selected
選項標籤有以下值:
<option value='1|11' $statusMsg1>Active</option>
<option value='2|11' $statusMsg2>Blocked</option>
它總是通過1|11
值!這應該是通過我選擇的選項值。我不明白爲什麼它的發生:(
啊..使用它!不調用'Ajax' :( –
@shibbirahmed我沒有看到它不會的原因..控制檯中的任何錯誤? –
在控制檯沒有錯誤 –