ajax从其中删除数据后如何获取更新的值?

发布于 2024-10-12 14:51:50 字数 1215 浏览 3 评论 0原文

我有一个带有缩略图的元素。我允许用户对他们的显示顺序进行排序(这会通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金兰素衣 2024-10-19 14:51:50

我的第一个猜测是这些项目是由插件缓存的。您可以通过调用检查项目来测试这一点,如下所示:

var items = $("#images ul").sortable( "option", "items" );

如果这不包含更新的项目列表,您可以再次设置它们

$("#images ul").sortable( "option", "items", 'li' );

此检查将在您的函数中包含注释的行之前进行,

//NEEDS TO GET THE UPDATED CONTENT

而不是尝试重新设置项目,如何销毁可排序并重新初始化。

$("#images ul").sortable("destroy"); // destroy
$("#images ul").sortable(); // init

My first guess would be that the items are cached by the plugin. You could test this by calling examining the items like so:

var items = $("#images ul").sortable( "option", "items" );

If this does not contain the updated list of items you can set them again

$("#images ul").sortable( "option", "items", 'li' );

This check would go in your function before the line where you have the comment

//NEEDS TO GET THE UPDATED CONTENT

Instead of trying to re-set the items, how about destroying the sortable and reinitializing.

$("#images ul").sortable("destroy"); // destroy
$("#images ul").sortable(); // init
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文