doulin4844 2011-06-13 06:55
浏览 59
已采纳

重定向到同一页面后如何调用jquery函数?

Let's say after my user fills a form and clicks the submit button, I want the user redirected to the same page with the form and a jquery animation will play. The header function is there to prevent the user from refreshing the page and resubmitting the same data.

UPDATE: I've decided to use $_SESSION to record the user's session to try to get the jquery animation to play after they get redirected to the same page:

<?php
session_start(); 

if (isset ($_POST['submit']))
{
$connect = mysql_connect("","","") or die("Error connecting to db");
mysql_select_db("") or die("Error connecting to db");

$text = $_POST['text'];



mysql_query ("INSERT INTO header VALUES('','$text')");

  $_SESSION['jq']=='a';
    header('Location: header.php');
    die();

}


if($_SESSION['jq']=='a') {
   $_SESSION['jq']='';

echo'
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

    $("div").hide(3000);

});
</script>';


}




?>



<html>
<head>

<style type="text/css">
#jquery {border:1px solid black;width:300px;}
</style>

</head>
<body>
<form name="header" action="header.php" method="post">


<input type="text" name="text" />
<input type="submit" name="submit" value="submit"    />
</form>
<div id="jquery">this is jquery animation</div>

</body>
</html>
  • 写回答

3条回答 默认 最新

  • duane9322 2011-06-13 08:50
    关注

    Use like this

    if (isset ($_POST['submit']))
    {
        $text = $_POST['text'];
        mysql_query ("INSERT INTO header VALUES('','$text')");
    
        //redirect to same page that user submitted form from
        header('Location: form.php?jq=a');
        die();
    }
    if($_GET['jq']=='a') {
       //play animation
       echo'<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
       <script type="text/javascript">
       $(document).ready(function(){
    
           //insert jquery animation code
    
       });
       </script>';
    }
    

    Or

    session_start();
    if (isset ($_POST['submit']))
    {
        $text = $_POST['text'];
        mysql_query ("INSERT INTO header VALUES('','$text')");
    
        //redirect to same page that user submitted form from
        //$_SESSION['jq']=='a'; commented for your understanding remove this in your code.
        $_SESSION['jq']='a';
        header('Location: form.php');
        die();
    }
    if($_SESSION['jq']=='a') {
       $_SESSION['jq']='';
       //play animation
       echo'<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
       <script type="text/javascript">
       $(document).ready(function(){
    
           //insert jquery animation code
    
       });
       </script>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决