删除文章,然后从下一页引入第一篇文章 [英] Delete an article and pull in the first one from next page

查看:131
本文介绍了删除文章,然后从下一页引入第一篇文章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个具有分页系统的博客(例如,每页5篇文章). 分页本身一切都很好,但是在每篇文章旁边,我都包含一个删除"按钮,允许管理员动态地删除(jquery)相关文章及其内容. 我现在想要的是在删除文章时附加"(不刷新)下一页的第一篇文章,在删除另一篇文章时第二篇,然后第三篇,依此类推. 如果我继续删除文章而不刷新,我希望这样做可以避免出现空白页面.

I'm trying to build a blog with a pagination system (ex. 5 articles per page). Everything is fine with the pagination itself but next to each article I included a "delete" button allowing the admin to remove dynamically (jquery)the related article and its content. What I want now is to "append" (without refreshing) the first article of the next page when I delete an article, the second when I delete another article, then the third and so on. I want this to avoid to have a blank page if I keep on deleting articles without refreshing.

我实际上正在使用php和mysql数据库来存储数据 为了分页,我正在使用与此类似的东西 链接.

I'm actually using php and a mysql database to store data for paginating I'm using something similar to this link.

推荐答案

我最初在重复项上回答,但认为可能会被删除,因此请在此处复制:

I originally answered on the duplicate, but think that might get deleted, so copying here:

jQuery使它变得简单易用.假设您有一个名为ajax/delete-article.php的php文件,该文件将要删除的商品ID作为参数,并将页面上最后一篇文章的商品ID作为参数,并返回HTML的HTML文件.下一篇.它还假定您所有的文章都具有"article"类,并且其ID为"article-230",其中230是ID号.我确定您可以将其调整为适合您自己的HTML结构.

jQuery makes it nice and easy. This assumes you've got a php file called ajax/delete-article.php which takes an article id to be deleted as a parameter, and the article id of the last article on the page as a parameter, and returns the HTML of the next article. It also assumes all your articles have the "article" class, and the id "article-230" where 230 is the ID number. I'm sure you can adapt it to your own HTML structure.

$('.article-delete').click(function (event) {
  $(this).closest('.article').remove(); // possibly use a more fancy-looking hide(), and remove on complete?

  var lastArticleId = $('.article').last().attr('id').replace('article-','');
  var thisArticleId = $(this).attr('id').replace('article-','');
  $.get('ajax/next-article.php?last-article=' + lastArticleId + '&article-to-delete=' + thisArticleId ,function (data) {
    $('#article-list').append(data);
  });
  event.preventDefault();
});

请注意,这只是一个粗糙的示例.鲁棒性将需要一些改进.它也未经测试,因此可能到处引发JS错误.

Note that this is just a rough example. Will require some improvements for robustness. Its also untested, so it might throw up JS errors everywhere.

这篇关于删除文章,然后从下一页引入第一篇文章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆