Passing Data to an AJAX Call
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