dongshao1156
2011-11-28 23:56
浏览 250
已采纳

如何成功重新加载包含的php页面?

I have a php page in which I want to include another php page, like this:

<?php
    include ("wrapper.php");
?>

It works just fine, but when I click on a div, which will trigger a javascript function like this:

function reloadNivoSlider () {
    $('#photo-show').fadeOut('slow', function () {
        $("#photo-show").load("nivo-slider/wrapper.php", function () {
            $('#photo-show').fadeIn('slow');
        })
    });
}

The div fades out and fades back in with the nivo slider loading forever. I tried to remove the animations, but the same happens. Could the MySQL request I do in wrapper.php be the reason of the problem? Does it stop the page from reloading? I actually don't know how $().load works, but I presume it reloads the page, right?

The wrapper.php file is:

<body>
<div id="wrapper">

    <div class="slider-wrapper theme-default">
        <div class="ribbon"></div>
        <div id="slider" class="nivoSlider">
            <?php
                mysql_connect(localhost,"root","");
                mysql_select_db("fotos") or die( "Unable to select database");

                $select = "SELECT * FROM 2a_mostra_kineret WHERE id='0';";
                $query = mysql_query($select);
                $row = mysql_fetch_assoc($query);

                $i = 0;

                while ($i <= 7) {
                    $verify = 1;
                    $random = rand(0,7);
                    // First Execution
                    if ($i == 0) {
                        $path[$i] = $row["path"] . $random . ".jpg";
                    }
                    // Other Executions
                    else {
                        while ($verify != 0) {
                            for ($s = 0; $s < $i; $s++) {
                                if ($row["path"] . $random . ".jpg" == $path[$s]) {
                                    $verify++;
                                    break;
                                }
                            }
                            if ($verify > 1) {
                                $random  = rand(0,7);
                                $verify = 1;
                            }
                            else $verify = 0;
                        }
                        $path[$i] = $row["path"] . $random . ".jpg";
                        //echo $random;
                    }
                    $i++;
                }

                for ($i = 0; $i <= 7; $i++) echo "<img src=\"$path[$i]\" alt=\"\" width=\"800\" height=\"600\"/>";

                mysql_close();
            ?>                              

        </div>
        <div id="htmlcaption" class="nivo-html-caption">
            <strong>This</strong> is an example of a <em>HTML</em> caption with <a href="#">a link</a>.
        </div>
    </div>

</div>
<script type="text/javascript" src="scripts/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="../jquery.nivo.slider.pack.js"></script>
<script type="text/javascript">
$(window).load(function() {
    $('#slider').nivoSlider();
});
</script>

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongqianzhan8325 2011-11-29 17:07
    已采纳

    No its not possible, ajax is the way. Check links http://api.jquery.com/jQuery.get/ http://api.jquery.com/category/ajax/

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongzi5062 2011-11-29 00:04

    Keep in mind that PHP is executed on the server. Once it's sent to the client you can no longer do any PHP. If you want JavaScript to 'fetch' new data from the server you'll have to use AJAX.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题