运行.each的最佳做法是什么,并通过ajax将值作为数组发送。
$( ".sortable li" ).each(function( index ) {
console.log($(this).data("trackid"));
});
这将在控制台窗口11,2,45,23,4,31中输出。
答案 0 :(得分:0)
Well you could use the push method to add the id's to an array. I've posted an array like this to PHP and it works well.
var theArray = [];
$( ".sortable li" ).each(function( index ) {
theArray.push($(this).data("trackid"));
});
// Send via Ajax
$.post(url,{ids:theArray},function(response){
// Code to handle response
});