新手编码员在这里试图从错误中学习。:)
我有三个文件(jquery.js、php.php 和 html.html)。
我正在尝试从 mySQL 数据库名称中获取信息trial1
。它只有一张名为 的表Score_Sheet
。
下面是 html.html 的代码
<!DOCTYPE html>
<html>
<head>
<script type="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src= "jquery.js" type = "text/javascript"></script>
</head>
<body>
<button id = "button"> Click to see value from SQL table</button>
<div id= "content"></div>
</body>
<html>
下面是 php.php 的代码
$link = mysqli_connect("localhost","root","","trial1");
$query = "SELECT * FROM Score_Sheet";
$show = mysqli_query($link, $query) or die ("Error");
echo "<table><tr><td>ID</td><td>UserID</td><td>Score</td></tr>";
while ($row = mysqli_fetch_array($show)){
echo "<tr><td>" . $row['ID'] . "</td><td>" . $row['UserID'] . "</td><td>" . $row['Score'] . "</td></tr>";
}
echo "</table>";
}
下面是 jquery.js 的代码
$(document).ready(function(){
$("#button").click(function(){
function show_all(){
$.ajax({
type = "POST",
url = "php.php",
success: function (data){
$("#content").html(data);
}
});
}
// show_all();
});
});
今天学到了一个好东西。谢谢大家。我不得不使用开发人员工具来查看发生了什么错误。错误是 ReferenceError: $ 未定义。然后我用谷歌搜索错误并使用这个内联链接论坛来修复它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句