gpt4 book ai didi

php - jQuery,需要 'sortreceive' ajax 调用和 POST 变量的帮助

转载 作者:行者123 更新时间:2023-11-29 09:18:06 25 4
gpt4 key购买 nike

我现在面临一个似乎超出我能力范围的困境!

我有一组使用“biglist”类连接的可排序对象。

我想要做的是绑定(bind) #biglist 的 sortreceive 回调(每当列表从另一个列表接收元素时就会进行)以获取元素的“boxnum”值(表示它来自哪个列表)并执行更新查询将 id 的 boxnum 值从 5(它来自的列表)更改为 7(列出它被拖动到的位置),以便状态持续存在。

所以交换会像这样发生(大致)

$( "#biglist" ).bind( "sortreceive", function(event, ui) {
ajax call to boxchange.php
create vars to represent elements 'boxnum' value and 'box moved to' value

});

然后在boxchange.php里面 ->

 $id = $_POST['id']
$box = $_POST['boxnum']
->update query SET boxid to new boxid WHERE id = posted ID of element

我希望这是有道理的。这似乎是让我的程序运行的一种非常巧妙的方法!非常感谢任何帮助。

EDIT:

只是清理了该函数,看看是否需要对其进行任何更改(我知道有,因为它看起来很草率)这个函数需要为每个可排序单独复制/更改,但它'至少让程序完全运行!

function ReceiveTwo() 
{
$('#sortable2').bind('sortreceive', function(event, ui)
{
boxnum = $(this).attr('boxnum');
id = $(this).attr('id');
$.ajax
({
url: "boxchange.php",
type: "POST",
data: boxnum, id,
success : function(feedback)
{
$('#data').html(feedback)
}

})
});
$('#sortable2').sortable("refresh");
});

最佳答案

$('#sortable2').bind('sortreceive', function(event, ui) {
$.ajax({
url: "boxchange.php",
type: "POST",
beforesend: function(){
boxnum = $(this).attr('boxnum');
id = $(this).attr('id');
},
data: {'boxnum': boxnum, 'id': id},
success : function(feedback) {
$('#data').html(feedback),
}
});
});

beforesend 是在 ajax 调用之前触发的事件。我相信在这里你可以设置你的属性来完成你想要的。

关于php - jQuery,需要 'sortreceive' ajax 调用和 POST 变量的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3425834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com