使用ajax调用加载页面的一部分。但是表单按钮不起作用

时间:2019-05-09 10:28:57

标签: php html mysql ajax

我有一个页面(index.html)。我正在使用ajax调用(load.php)刷新它。 load.php从数据库获取数据。以表格形式显示数据。每个表格行都有一个选择按钮,它将选择该行以进行进一步的计算。问题是按钮不起作用。没有ajax调用,就可以正常工作。

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
  <meta charset="utf-8">
  <title></title>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
<script type="text/javascript" src="jquery-1.9.0.min.js"></script>
 <script type="text/javascript" src="myScript.js"></script></script>

  </head>
  <body>
    <div id="auto">

     </div>
  </body>
</html>


load.php

<table class="dataTable">
 <tr>
  <th>Serial</th>
  <th>Date</th>
  <th>Voltage</th>
  <th>Current</th>

 </tr>

 <?php

 include ("DBconnect.php");
 $conn= mysqli_connect( $dbhost, $dbuser, $dbpass, $db );
 if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
 }
 $sql = "SELECT Date, Voltage, Current FROM dataTable WHERE  Date >= (CURDATE() - INTERVAL 10 DAY)  ORDER BY Datum DESC";

 $result = $conn->query($sql);
 $i=1;
 if ($result->num_rows > 0) {
  while($row = $result->fetch_assoc()) {

//form starts
//action- another page action.php
//submit button doesn't work!!!


 echo "<form action = 'action.php' method =get target=_blank>";
 echo "<tr></tr>";
     echo '<tr>';
     echo"<td>" . $i. "</td>";
     echo"<td>" . $row["Date"]. "</td>";
     echo"<td>". $row["Voltage"] . "</td>";
     echo"<td>". $row["Current"]. "</td>";

     echo "<td>".' <input type="hidden" name="getTime" value="' . $row["Date"] . '" />' . "</td>";
     echo "<td>".' <input type=submit    name=Submit value=select/>' . "</td>";
     echo '</tr>';
     $i++;
 echo "</form>";
}
echo "</table>";
} else { echo "0 results"; }
$conn->close();

?>

</table>

myScript.js

$(document).ready( function(){
$('#auto').load('load.php');
refresh();
});

function refresh()
{
    setTimeout( function() {
      $('#auto').fadeOut('slow').load('load.php').fadeIn('slow');
      refresh();
    }, 10000);
}

0 个答案:

没有答案