Php 在JQuery sortable()函数期间传递列表项值
我试图在将列表项放入另一个列表后,将无序列表、列表项中的信息传递给ajax请求 这是一个JQuery,它拾取列表项所放入的列#id,但是获取$row['id']的代码拾取每个列表中的第一个项,而不是我正在排序的特定项 (我正在使用php迭代两个列表中的列表项——我已经删除了不必要的php代码)Php 在JQuery sortable()函数期间传递列表项值,php,jquery,html,Php,Jquery,Html,我试图在将列表项放入另一个列表后,将无序列表、列表项中的信息传递给ajax请求 这是一个JQuery,它拾取列表项所放入的列#id,但是获取$row['id']的代码拾取每个列表中的第一个项,而不是我正在排序的特定项 (我正在使用php迭代两个列表中的列表项——我已经删除了不必要的php代码) $(文档).ready(函数(){ $(“.sortable”).sortable({ 连接到:“.sortable”, 接收:函数(){ var column=$(this).closest('div
$(文档).ready(函数(){
$(“.sortable”).sortable({
连接到:“.sortable”,
接收:函数(){
var column=$(this).closest('div.box').attr('id');
var id=$(this.find('span').html();
$.ajax({
url:“update_column.php”,
类型:“POST”,
数据:“column=“+column+”&id=“+id
});
警报(列+id)
}
})
.disableSelection();
});
我正在使用alert()给我一些视觉反馈。这是HTML代码:
<div id="one" class="box">
<ul class="sortable">
<li>
<div class="card">
<p>' . $row['customer'] . '</p>
<p>' . $row['ponumber'] . '</p>
<p class="hide"><b>ID:</b><span>' . $row['id'] . '</span></p>
<p class="hide">' . $row['misc'] . '</p>
</div>
</li>
</ul>
</div>
<div id="two" class="box">
<ul class="sortable">
<li>
<div class="card">
<p>' . $row['customer'] . '</p>
<p>' . $row['ponumber'] . '</p>
<p class="hide"><b>ID:</b><span id="id">' . $row['id'] . '</span></p>
<p class="hide">' . $row['misc'] . '</p>
</div>
</li>
</ul>
</div>
-
"$第[‘客户’]行。'
"$行['ponumber']。'
ID:”$行['id']。'
”$行['misc']。'
-
"$第[‘客户’]行。'
"$行['ponumber']。'
ID:”$行['id']。'
”$行['misc']。'
我是一个自学成才的程序员,已经编程3个月了,所以我为任何新手的错误道歉。我已经更新了你的js,现在可以使用了。我已经在需要的地方添加了评论
$(document).ready(function(){
$(".sortable").sortable({
connectWith : ".sortable",
receive : function(event, ui){
//changed this to be use parent()
var column = $(this).parent().attr('id');
//get the current dragged item - as per http://jqueryui.com/demos/sortable/#event-receive
var index = ui.item.index() + 1 ;
//get the id from the span using the column we got in the first step and index we got above
var id = $("#"+column+" li:nth-child("+index+") span").html();
$.ajax({
url: "update_column.php",
type:"POST",
data: "column="+column+"&id="+id
});
}
}).disableSelection();
});
我真的很感谢你抽出时间来帮助我!它不仅起作用,你还帮助我理解了原因。谢谢你,德鲁。
$(document).ready(function(){
$(".sortable").sortable({
connectWith : ".sortable",
receive : function(event, ui){
//changed this to be use parent()
var column = $(this).parent().attr('id');
//get the current dragged item - as per http://jqueryui.com/demos/sortable/#event-receive
var index = ui.item.index() + 1 ;
//get the id from the span using the column we got in the first step and index we got above
var id = $("#"+column+" li:nth-child("+index+") span").html();
$.ajax({
url: "update_column.php",
type:"POST",
data: "column="+column+"&id="+id
});
}
}).disableSelection();
});