0

嘿,所以我试图通过 AJAX 调用将数据放入这个 div

        <div class="scroll-pane2 blue small" style="">
            <p id="bulletinBodyArea" style="margin-right:20px;"></p>    
        </div>

当单击从数据库提供的链接之一时,将触发 AJAX

        <div class="bulletinSectionAccordion rounded">
            <p class="blue" style="font-size:19px;margin-left:23px;margin-top:15px;margin-bottom:10px;">Archives</p>
        <?php


            $query = "SELECT * FROM `bulletin`  LEFT JOIN `bulletininschool` ON `bulletin`.`id`=`bulletininschool`.`bulletin` WHERE `school` = 2 ";
            $result=$connection->query($query);

          while($row = $result->fetch_array()) {
            echo  '<p class="medium titi" style="margin-left:23px;">'.$row['title'].'</p>';
          }
        ?>
        </div>

它被调用然后传递数据

  $(".titi").click(
        getBody
  );

    function getBody(){
      $("#bulletinBodyArea").load('update/getBody.php');
    };

这是 AJAX 功能

<?php
$section='bulletin';
$table="bulletin";
$schoolSelectorTable="bulletininschool";
$schoolSelector="bulletin";

    $db_host = "localhost";
    $db_user = "root";
    $db_pass = "";
    $db_name = "isl";


mysql_connect($db_host, $db_user, $db_pass, $db_name);
mysql_select_db("isl") or die(mysql_error());


$states = mysql_query("SELECT * FROM `bulletin` LEFT JOIN `bulletininschool` ON `bulletin`.`id`=`bulletininschool`.`bulletin` WHERE `school` = 2" );


while($state = mysql_fetch_array($states)){
    echo "<p>".$state['body']."</p>";
}
?>

现在,从数据库提供的单击链接实际上是文章标题,然后当单击特定标题时,AJAX 调用应该去获取与该文章关联的正文文本。但我无法理解我应该如何度过难关。我正在做正确的查询并获取标题和正文,但我无法弄清楚如何将它们关联起来。我是否将变量传递给 AJAX 调用?

谢谢

4

1 回答 1

0
  $(document.ready( function() {
        $(".titi").click( function() { // you had a syntax error here also
             getBody();
        });
  });
  function getBody(){
        $("#bulletinBodyArea").load('update/getBody.php');
  };

您的代码中有语法错误,它应该是 getBody(); 不仅getBody!使用文件准备功能!

于 2012-12-27T06:06:17.540 回答