【发布时间】:2014-05-09 21:26:25
【问题描述】:
我正在使用 DataTables,这是我的场景:
1)我有一个下拉菜单,其中包含一些用户名和他们的正确 ID;
2)我有一个空的数据表;
3)我想检测从下拉菜单中选择一行的用户ID,使用DataTables的data:属性将其传递给server_processing.php(DB查询),并在数据表中显示DB查询的结果。
下拉代码:
<select id="selezione_user" name="selezione_user" class="select2 form-control">
<option value="">Seleziona</option>
<?php $query=mysql_query("SELECT user_id,nome FROM user ORDER BY nome",$conn);
while($row=mysql_fetch_array($query)){
echo "<option value='$row[user_id]'>$row[nome]</option>";
}?>
</select>
数据表 (HTML) 代码:
<table class="table table-striped" id="prova">
<thead>
<tr>
<th>User</th>
<th>Comune</th>
<th>Mail</th>
<th>Stato</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
DataTable (JS) 代码
$(document).ready(function() {
var oTable = $('#prova').dataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "scripts/server_processing.php",
"data": {
"user_id": null //set to show empty DataTable
}
},
});
$('#selezione_user').change(function() {
aoData.push({
"user_id": this.value
})
});
});
但是上面的代码不起作用,这个问题让我发疯,我希望有人能帮助我。 谢谢大家。 贾科莫。
编辑
我通过删除 data: 并以这种方式更改 DataTables(JQuery) 函数解决了我的问题:
$('#selezione_centri').change(function() {
var valore = this.value;
var string = ('scripts/server_processing.php?id_professionista='+valore);
table.ajax.url(string).load();
table.reload();
});
【问题讨论】:
标签: javascript php jquery datatable