[英]How to submit an array using HTML and Ajax and send it to PHP as array?
[英]Send objects array to php with ajax and submit to SQL
我正在尝试创建一个可嵌套列表,可以通过拖放对其进行重新排序,并且直到现在为止都做得很好,非常感谢;-),但是...
一切都按预期进行,但是当我放下一个项目但不确定如何这样做时,我希望能够通过php将tor命令保存到db中?
当我放下一个项目时,我得到了这样的对象数组:
[对象,对象,对象,对象,对象,对象,对象]
每个对象和项目以及一个itemId:
<li data-item="<?=$row['name']?>" data-item-id="<?=$row['fk_module_id']?>">
如何通过ajax将其传递给php,以及如何在php脚本中打开对象?
这是处理dragDrop部分的jQuery:
$("#modules-active").on('nestable-stop', function(ev)
{
var serialized = $(this).data('nestable').serialize(),
str = '';
console.log( serialized );
console.log( $(this).data('nestable').list() );
$.post( "savelist.php", { list: serialized }).done(function( data ) {
});
});
回顾一下:如何将其正确传递给php,如何打开并将其保存在php页面上?
任何帮助表示赞赏,并在此先感谢:-)
<li class='data' data-item="<?=$row['name']?>" data-item-id="<?=$row['fk_module_id']?>">
jQuery(document).ready(function($){
url = " Your php file url/savelist.php";
var allVals = [];
$('.btn').click(function(){
$('.data').each(function() {
allVals.push($(this).val());
});
$.post(url,{ array : allVals }, function(response,status){
if(status == 'success'){
//ur stuffs
return status;
}
})
})
})
它可以帮助你..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.