ajax从其中删除数据后如何获取更新的值?
我有一个带有缩略图的元素。我允许用户对他们的显示顺序进行排序(这会通过 ajax 触发对数据库的更新)。我还允许他们删除图像(删除后,会触发更新所有剩余图像的显示顺序的请求)。
我认为我的问题是绑定或实时,但我不知道在哪里应用它。
删除时触发的数组包含页面加载时图像的所有 id。问题是,在删除图像后,数组仍然包含原始 id(包括被删除的 id),因此在 ajax 从元素内部删除内容后,显然不会刷新元素的值。我需要告诉它去获取刷新的内容...
从我所读到的内容来看,这是正常的,但我不明白如何将其与我的日常工作联系起来。我需要在删除后触发批量重新排序。
有什么想法大师吗?
$('a.delimg').click(function(){
var parent = $(this).parent().parent();
var id = $(this).attr('id');
$.ajax({
type: "POST",
url: "../updateImages.php",
data: "action=delete&id=" + id,
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
$.jnotify("<strong>Deleting This Image & Updating The Image Order</strong>", 5000);
},
success: function(data) {
parent.slideUp(300,function() {
parent.remove();
$("#images ul").sortable(function() { //NEEDS TO GET THE UPDATED CONTENT
var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
$.post("../updateImages.php", order, function(theResponse){
$.jnotify("<strong>" + theResponse + "</strong>", 2000);
});
});
});
}
});
return false;
});
感谢您提供的任何帮助。
I have a an element with thumbnails. I allow users to sort their display order (which fires off an update to the DB via ajax). I also allow them to delete images (which, after deletion, fires off a request to update the display order for all remaining images).
My problem is with binding or live I think, but I don't know where to apply it.
The array fired off upon delete contains ALL the ids for the images that were there on page load. The issue is that after they delete an image the array STILL contains the original ids (including the one that was deleted) so it is obviously not refreshing the value of the element after ajax has removed things from inside it. I need to tell it to go get the refreshed contents...
From what I have been reading, this is normal but I don't understand how to tie it into my routine. I need to trigger the mass re-ordering after any deletion.
Any ideas gurus?
$('a.delimg').click(function(){
var parent = $(this).parent().parent();
var id = $(this).attr('id');
$.ajax({
type: "POST",
url: "../updateImages.php",
data: "action=delete&id=" + id,
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
$.jnotify("<strong>Deleting This Image & Updating The Image Order</strong>", 5000);
},
success: function(data) {
parent.slideUp(300,function() {
parent.remove();
$("#images ul").sortable(function() { //NEEDS TO GET THE UPDATED CONTENT
var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
$.post("../updateImages.php", order, function(theResponse){
$.jnotify("<strong>" + theResponse + "</strong>", 2000);
});
});
});
}
});
return false;
});
Thanks for any help you can be.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的第一个猜测是这些项目是由插件缓存的。您可以通过调用检查项目来测试这一点,如下所示:
如果这不包含更新的项目列表,您可以再次设置它们
此检查将在您的函数中包含注释的行之前进行,
而不是尝试重新设置项目,如何销毁可排序并重新初始化。
My first guess would be that the items are cached by the plugin. You could test this by calling examining the items like so:
If this does not contain the updated list of items you can set them again
This check would go in your function before the line where you have the comment
Instead of trying to re-set the items, how about destroying the sortable and reinitializing.