每次删除div时调用PHP函数(Calling PHP function each time a div is dropped)

系统教程 行业动态 更新时间:2024-06-14 16:57:39
每次删除div时调用PHP函数(Calling PHP function each time a div is dropped)

我有一个可拖动的元素,我想在每次删除元素时调用PHP函数(基本上是为了保存它的位置 - 像素从顶部和左边到mysql数据库)。 如何接近它? AJAX?

I have a draggable element and I would like to call PHP function each time the element is dropped (basically to save its position - pixels from top and left to mysql database). How to approach it? AJAX?

最满意答案

$("#droppable").droppable({ drop: function() { $.get('http://mysite.com/dragged.php?droppedID='+this.id); } });

编辑

如果你想要draggable的id(而不是它的内容),你需要在设置drop回调时使用ui参数:

$( "#draggable" ).draggable(); $("#droppable").droppable({ drop: function(event, ui) { $.get('http://mysite.com/dragged.php?droppedID='+ui.draggable.attr('id')); } }); $("#droppable").droppable({ drop: function() { $.get('http://mysite.com/dragged.php?droppedID='+this.id); } });

EDIT

If you want the id of the draggable (and not what it was dropped on), you need to use the ui parameter when you setup the drop callback:

$( "#draggable" ).draggable(); $("#droppable").droppable({ drop: function(event, ui) { $.get('http://mysite.com/dragged.php?droppedID='+ui.draggable.attr('id')); } });

更多推荐

本文发布于:2023-04-13 11:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/a51afb301c29290388381fea06cc42b7.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时调   函数   PHP   div   dropped

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!