Javascript JQuery可排序序列化
我正在使用JQuery对一个表进行排序,我的JQuery运行没有问题,但我无法使序列化正常工作。我想知道是否有人能帮我解释一下我需要做什么 所以我的html是Javascript JQuery可排序序列化,javascript,jquery,html,ajax,jquery-ui,Javascript,Jquery,Html,Ajax,Jquery Ui,我正在使用JQuery对一个表进行排序,我的JQuery运行没有问题,但我无法使序列化正常工作。我想知道是否有人能帮我解释一下我需要做什么 所以我的html是 <table class="table table-striped table-bordered sorted_table" id="positionstable"> <tbody> <tr> <th class="sectionname" cols
<table class="table table-striped table-bordered sorted_table" id="positionstable">
<tbody>
<tr>
<th class="sectionname" colspan="1">Position</th>
</tr>
<tr data-id="2">
<td class=" ">Item 2</td>
</tr>
<tr data-id="1">
<td class=" ">Item 1</td>
</tr>
<tr data-id="3">
<td class=" ">Item 3</td>
</tr>
<tr data-id="4">
<td class=" ">Item 4</td>
</tr>
</tbody>
</table>
位置
项目2
项目1
项目3
项目4
我的JQuery是:
$('.sorted_table').sortable({
containerSelector: 'table',
itemPath: '> tbody',
itemSelector: 'tr',
placeholder: '<tr class="placeholder"/>',
onDrop: function (item, container, _super) {
var dataToSend = $('.sorted_table').sortable("serialize").get();
console.log(dataToSend)
$.ajax({
url: "ajax_action.php",
type: "post",
data: dataToSend,
cache: false,
dataType: "json",
success: function () {}
});
//_super(item, container);
}
})
$('.sorted_table')。sortable({
containerSelector:'表',
itemPath:“>tbody”,
itemSelector:'tr',
占位符:“”,
onDrop:功能(项目、容器、超级){
var dataToSend=$('.sorted_table').sortable(“serialize”).get();
console.log(dataToSend)
$.ajax({
url:“ajax_action.php”,
类型:“post”,
数据:dataToSend,
cache:false,
数据类型:“json”,
成功:函数(){}
});
//_超级(物品、容器);
}
})
您还可以在以下位置找到代码:
我希望将一个ID数组发送到我的ajax脚本
我期待着你的任何帮助和建议
问候
James通常serialize处理表单元素并生成JSON对象,使用每个字段的名称作为键,元素的值作为值 您可以轻松地生成序列化对象,就像在表行中循环一样
$('.sorted_table').sortable({
containerSelector: 'table',
itemPath: '> tbody',
itemSelector: 'tr',
placeholder: '<tr class="placeholder"/>',
onDrop: function (item, container, _super) {
var obj = jQuery('.sorted_table tr').map(function(){
return 'trvalue[]=' + jQuery (this).attr("data-id");
}).get();
console.log(obj)
//do the ajax call
}
})
$('.sorted_table')。sortable({
containerSelector:'表',
itemPath:“>tbody”,
itemSelector:'tr',
占位符:“”,
onDrop:功能(项目、容器、超级){
var obj=jQuery('.sorted_table tr').map(函数(){
返回'trvalue[]='+jQuery(this.attr)(“数据id”);
}).get();
控制台日志(obj)
//执行ajax调用
}
})