dongmou5628 2012-12-27 05:32
浏览 19

将数据传递给AJAX调用

Hey all so Im trying to put data through an AJAX call into this div

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

The AJAX is being triggered when one clicks on one of the links being fed from the database

        <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>

It gets called and then passes the data

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

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

And this is the AJAX function

<?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>";
}
?>

Now the links that one clicks that are fed from the database are actually article titles, and then when one clicks on a specific title the AJAX call should go and fetch the body text associated with that article. But I'm having trouble understanding how I should go through that. I'm doing the correct queries and getting the titles and the bodies but I just cant figure out how to associate them. Do I pass a variable to the AJAX call?

Thank you

  • 写回答

1条回答 默认 最新

  • doucigua0278 2012-12-27 06:06
    关注
      $(document.ready( function() {
            $(".titi").click( function() { // you had a syntax error here also
                 getBody();
            });
      });
      function getBody(){
            $("#bulletinBodyArea").load('update/getBody.php');
      };
    

    You had a syntax error in your code it should be getBody(); not only getBody! Use document ready function!

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog