如何使用ajax / php在两个选项卡之间切换内容? [英] How do I toggle content between two tabs using ajax/php?

查看:94
本文介绍了如何使用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在两个选项卡之间切换内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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