【问题标题】:How to Load In Content with jQuery?如何使用 jQuery 加载内容?
【发布时间】:2010-04-01 23:42:30
【问题描述】:

我正在尝试将 ajax 功能添加到我的分页中,以便在同一页面中加载内容,而不是用户在单击页面链接时必须导航到另一个页面。

我应该提到我正在使用this php pagination class

作为 jquery 的新手,我不确定如何正确使用分页类。

这是主页的样子:

<?php
$categoryId=$_GET['category'];
echo $categoryId;
?>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery_page.js"></script>

<?php
    //Include the PS_Pagination class
    include('ps_pagination.php');
    //Connect to mysql db
    $conn = mysql_connect('localhost', 'root', 'root');
    mysql_select_db('ajax_demo',$conn);
    $sql = "select * from explore where category='$categoryId'";
    //Create a PS_Pagination object
    $pager = new PS_Pagination($conn, $sql, 3, 11, 'param1=value1&param2=value2');
    //The paginate() function returns a mysql
    //result set for the current page
    $rs = $pager->paginate();
    //Loop through the result set

echo "<table width='800px'>";

    while($row = mysql_fetch_assoc($rs)) {            

                echo "<tr>";
                    echo"<td>";
                    echo $row['id'];
                    echo"</td>";

                    echo"<td>";
                    echo $row['site_description'];
                    echo"</td>";

                    echo"<td>";
                    echo $row['site_price'];
                    echo"</td>";
                echo "</tr>";

    }
echo "</table>";

        echo "<ul id='pagination'>";

            echo "<li>";
            //Display the navigation
            echo $pager->renderFullNav();
            echo "</li>";

        echo "</ul>";

?>

<div id="loading" ></div>
<div id="content" ></div>

<a href="#" class="category" id="marketing">Marketing</a>

<a href="#" class="category" id="automotive">Automotive</a>

<a href="#" class="category" id="sports">Sports</a>

对此的任何帮助都会很棒。谢谢。

【问题讨论】:

  • 您遇到的具体问题是什么(而不仅仅是“我不确定该怎么做”)?例如,我在此脚本中看不到任何 ajax 调用。那么问题是否与一般如何设置分页类有关?或者如何使用 jQuery Ajax?
  • 我不确定如何执行 jquery,所以当用户点击页面 2 时,jquery 将加载页面 2 而不会将用户发送到另一个页面。

标签: php jquery class pagination


【解决方案1】:
$("a.category").live("click", showContent)

function showContent()
{
   $("#content").load("/url/path/" + $(this).attr("id"));
}

将加载 /url/path/marketing、/url/path/automotive 或 /url/path/sports

进入内容div

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 2023-03-08
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多