我的代码:
<script type="text/javascript">
$(document).ready(function() {
// Initialise the table
$('#admintabel').tableDnD({
onDrop: function(table, row) {
}
});
});
</script>如何创建一个对示例/sort的ajax调用,其中包含参数位置和ID,如:[position, ID] onDrop?我的桌子应该是什么样的。
更新:
我正在尝试创建一个数组,如:
BREDBANDS[id] 1
BREDBANDS[id] 2
BREDBANDS[id] 3我目前的测试数据:
data: {
BREDBANDS: [1, 2, 3] },它发布的信息如下:
BREDBANDS[] 1
BREDBANDS[] 2
BREDBANDS[] 3给出了一个500的错误。
将数据发布到的Rails操作:
def sort
params[:bredbands].each_with_index do |id, index|
Bredband.update_all(['position=?', index+1], ['id=?', id])
end
render :nothing => true
end发布于 2011-10-11 06:24:26
很难理解您实际要求的是什么,但是应该以以下两种方式中的任何一种方式来发出Ajax请求:
$.ajax({
type: "GET",
url: "/sort?" + $.tableDnD.serialize(),
success: function(){
...
}
});或
$.ajax({
type: "POST",
url: "/sort",
data: $("tr", "$admintabel").map(function(){
return this.id;
}),
success: function(){
...
}
});但是,看起来您需要为您的TR元素提供it。那么你应该可以把它叫做:
$.tableDnD.serialize();它将序列化表及其行ID的数据。
https://stackoverflow.com/questions/7722035
复制相似问题