简体   繁体   中英

Display a method when div is displaying using show()

I have create an html code like this. When div #Loading_Page8 is displaying after clicking on link #Loading_Page7 I need to call a function in ABC.js. It has an Ajax function which runs a query in PQR.php. Here I have given a sample of my html page. .js file as well as the .php file

<html>
  <title></title>
  <head>
    <script>
      $(document).ready(function () {
        $("#Loading_Page8").hide();

        $("#EditForms").click(function () {
          $("#Loading_Page7").hide();
          $("#Loading_Page8").show();
            return false;
          });     
        });
      </script>
    </head>

    <body>   
      <div id="Loading_Page7">
        <div id="EditForms" class="AddUser">
          <a href=""><span>Edit/Delete Forms</span>
        </div>      
      </div>
      <div id="Loading_Page8">
        <label>Display Data</label>
        <div id="DisplayFormDetails" style="position: absolute; top:240px; width:1000px;"></div>
      </div>
    </body>
</html>

ABC.js file

 function ABC {
     $.ajax({ //create an ajax request to load_page.php
         type: "GET",
         url: "UpdateData.php",
         dataType: "html", //expect html to be returned                
         success: function (response) {
             $("#DisplayFormDetails").html(response);
             //alert(response);
         }
     });
 }

And finally this is the .php file

<?php
include 'connectionPHP.php';

$result = mysqli_query($con, "SELECT * FROM Form");

echo "<table border='1' >
    <tr>
    <td align=center> <b>Roll No</b></td>
    <td align=center><b>Name</b></td>
    <td align=center><b>Address</b></td>
    <td align=center><b>Stream</b></td></td>
    <td align=center><b>Status</b></td>";

while ($data = mysqli_fetch_row($result)) {
    echo "<tr>";
    echo "<td align=center>$data[0]</td>";
    echo "<td align=center>$data[1]</td>";
    echo "<td align=center>$data[2]</td>";
    echo "<td align=center>$data[3]</td>";
    echo "<td align=center>$data[4]</td>";
    echo "</tr>";
}
echo "</table>";
?>

The problem I have is how can I execute the function ABC. I don't know how to run ajax function when the #Loading_Page8 is displaying. The reason I take this into 3 separate file is I need to generalize them instead of re-writing the codes since I have many more links like <div id="EditForms" class="AddUser"><a href=""><span>Edit/Delete Forms</span></div .

And my second question is if there are more queries written in the PQR.php file how can I execute a specific query and send the echoed value to the ajax function/

First, you need to correct

function ABC{ 

to

function ABC() {

Then, just add call to your function:

$("#EditForms").click(function(){
  $("#Loading_Page7").hide();
  $("#Loading_Page8").show();
  ABC();
  return false;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM