现在我正在学习如何制作具有按钮功能的网络应用程序。单击按钮功能时,它会从服务器检索数据,然后将其打印在div中。数据只有一行。但是我无法通过垃圾邮件发送按钮,因为每次点击按钮都不会立即检索数据。在检索新数据之前需要大量的点击。这是我实施它的方式吗?
继承我的代码:
connection.php
.
.
.
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
mysql.php
<?php
require_once("connection.php");
$sql = "SELECT applename, appletype, applequantity, appleprice FROM
drugs";
$result = $conn->query($sql);
$numOfRows = $result->num_rows;
$randomNum = rand(1, $numOfRows);
$sql = "SELECT applename, appletype, drugquantity, drugdirection FROM drugs
LIMIT $randomNum,1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<div>
<span>" .$row["drugname"]." </span>
<span>" .$row["drugstrength"]." </span>
<span> #".$row["drugquantity"]." </span>
<p>".$row["drugdirection"]." </p>
</div>";
}
}
else {
echo "0 results";
}
$result->close();
$conn->close();
?>
我的.js文件有一个按钮,当点击执行此功能时
function dataRetrive(){
console.log("php");
$('#div1').load("mysql.php");
}
感谢任何帮助。先感谢您。