我已将内容分为两个标签,并使用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在两个选项卡之间切换内容?
发布评论