![](/img/trans.png)
[英]I need some help. Why do i get this JavaScript error message and how can i fix this?
[英]JQuery , PHP and mySQL Help. I do not understand why this is not working
新手编码员在这里试图从错误中学习。 :)
我有三个文件(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();
});
});
这个
{
type = "POST",
url = "php.php"
//...
}
不是你应该在 JS 中定义对象文字的方式。 尝试这个:
{
type: "POST",
url: "php.php"
//...
}
顺便说一句,浏览器的调试控制台是任何程序员最好的朋友,不仅仅是菜鸟;)
今天学到了一个好东西。 谢谢大家。 我不得不使用开发人员工具来查看发生了什么错误。 错误是 ReferenceError: $ 未定义。 然后我用谷歌搜索错误并使用这个内联链接论坛来修复它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.