我正在尝试从一个非常基本的网页切换到一个anthor页面,但是当我点击getAll
时,我将面临一些问题。
我以前的网页(那个令人讨厌的网页)
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<button onclick="getAll()"> Get All The Users </button>
<div id="users"></div>
<script>
function getAll()
{
$("#users").html("");
$.getJSON("http://localhost:8080/users", function(data)
{
for (var i in data) {
$('#users').append("<p>ID: " + data[i].id + "</p>")
$('#users').append("<p>First name: " + data[i].fname + "</p>")
$('#users').append("<p>Last name: " + data[i].lname + "</p><br>")
}
});
}
</script>
</body>
</html>
以下是错误:
Uncaught ReferenceError: getAll is not defined
at HTMLButtonElement.onclick (testt.html:96)
onclick @ @ testt.html:96
testt.html:145
Uncaught ReferenceError: screenfull is not defined
at HTMLDivElement.<anonymous> (testt.html:145)
(anonymous) @ testt.html:145
尼娜回答后,编辑了,我得到了想要的结果,但是主页看起来如下:
所以它扭曲了我主页的上部。
发布于 2017-08-10 05:16:40
你需要改变
<div id="requestfs">/div>
至
<div id="requestfs"></div>
你需要改变这一行
$.getJSON("http://localhost:8080/users" , function(data[i])
// ^^^
to (没有索引)
$.getJSON("http://localhost:8080/users" , function(data)
至少在使用之前,您需要将库包含在某个地方。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
可选,您也可以使用type属性。
<script type="text/javascript">
发布于 2017-08-10 05:29:35
当您声明一个函数时,{
应该与function
关键字位于同一行。例如:
function foo() {
}
您应该更改所有这些(注意,它们位于第110行和第20行)。
接下来,在队伍里
$.getJSON("http://localhost:8080/users" , function(data[i]) {
function (data[i])
应该是function (data)
此外,请记住包括jquery库。
https://stackoverflow.com/questions/45614745
复制