如何使用ajax / php在两个选项卡之间切换内容?

编程入门 行业动态 更新时间:2024-10-28 01:14:41
本文介绍了如何使用ajax / php在两个选项卡之间切换内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已将内容分为两个标签,并使用javascript在两个标签之间切换。

I have divided my content in two tabs and switching between two tabs with javascript.

<div class='tab-container'> <div class='tab-1'> <?php $sql="SELECT * FROM posts WHERE status='tab1'"; echo "<div class='db' <h2>post</h2></div>"; ?> </div> <div class='tab-2'> <?php $sql="SELECT * FROM posts WHERE status='tab2'"; echo "<div class='db' <h2>post</h2></div>"; ?> </div> </div>

Php代码通过WHERE子句select在制表符之间划分内容*来自status = tab1的帖子;所以要从一个标签中删除帖子,下面给出的ajax请求会触发php代码,它会更新从tab1到tab2的内容状态。

Php code divides content between tabs through WHERE clause select * from posts where status=tab1; so to remove post from one tab ajax request given below triggers php code which updates status of content from tab1 to tab2.

<script type="text/javascript"> $(function() { $(".restore").click(function(){ var element = $(this); var del_id = element.attr("id"); var info = 'id=' + del_id; if(confirm("Move this post?")) { $.ajax({ type: "GET", url: "restorepost.php", data: info, success: function(){ } }); $(this).parents(".db").animate({ backgroundColor: "#fbc7c7" }, "fast") .animate({ opacity: "hide" }, "slow"); } return false; }); }); </script>

因此该帖子已从tab1中删除。这里的想法是通过ajax将帖子从一个标签移动到另一个标签。 javascript在从一个标签中删除帖子时效果很好但是为了使该帖子出现在另一个标签中我必须重新加载页面,因为我没有使用ajax。所以问题是我没有得到如何通过ajax动态地将该帖子添加到另一个选项卡而不刷新页面。

So that post is removed from tab1. Idea here is to move post from one tab to another through ajax. javascript works good on removing post from one tab however for making that post appear in another tab I have to reload page as I haven't used ajax for that. So problem is I don't get how to add that post dynamically to another tab through ajax without refreshing page.

推荐答案

sql = SELECT * FROM posts WHERE status ='tab1'; echo < div class =' db'< h2> post< / h2>< / div>; ?> < / div > < div class =' tab-2' > <? php sql="SELECT * FROM posts WHERE status='tab1'"; echo "<div class='db' <h2>post</h2></div>"; ?> </div> <div class='tab-2'> <?php

sql = SELECT * FROM发布WHERE status ='tab2'; echo < div class =' db'< h2> post< / h2>< / div>; ?> < / div > < / div > sql="SELECT * FROM posts WHERE status='tab2'"; echo "<div class='db' <h2>post</h2></div>"; ?> </div> </div>

Php代码通过WHERE子句select在制表符之间划分内容*来自status = tab1的帖子;所以要从一个标签中删除帖子,下面给出的ajax请求会触发php代码,它会更新从tab1到tab2的内容状态。

Php code divides content between tabs through WHERE clause select * from posts where status=tab1; so to remove post from one tab ajax request given below triggers php code which updates status of content from tab1 to tab2.

<script type="text/javascript">

( function (){

更多推荐

如何使用ajax / php在两个选项卡之间切换内容?

本文发布于:2023-11-27 20:47:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639547.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   选项卡   两个   内容   php

发布评论

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

>www.elefans.com

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