javascript - jQuery .each best practice to format and send via ajax -
what best practice run .each , send value array via ajax.
$( ".sortable li" ).each(function( index ) { console.log($(this).data("trackid")); });
this output in console window 11,2,45,23,4,31.
well use push method add id's array. i've posted array php , works well.
var thearray = []; $( ".sortable li" ).each(function( index ) { thearray.push($(this).data("trackid")); }); // send via ajax $.post(url,{ids:thearray},function(response){ // code handle response });
Comments
Post a Comment