【发布时间】:2016-02-11 03:00:55
【问题描述】:
我在一个简单的 jsp 上有这个错误: 未捕获的 ReferenceError: $ 未定义
我刚刚尝试在 Eclipse 上调用另一个项目的服务休息,但它似乎不起作用..
代码在这里:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script rel="javascript" type="text/javascript" href="js/jquery-1.11.3.min.js" />
</head>
<body>
<script>
var people = {
"address": "Street 12",
"name": "twelve",
"id": 12,
"surname": "twelve"
};
function sendobject() {
$.ajax({
type: "POST",
url: "http://localhost:8080/HibernateTutorialWeb/rest/person/post",
data: markers,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
alert(data);
},
failure: function(errMsg) {
alert(errMsg);
}
});
}
</script>
<input type="button" onclick="sendobject()" value="send"> </input>
</body>
</<html>
更新:
尝试使用 Google CDN 的 jQuery,但仍然无法正常工作
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
Uncaught ReferenceError: $ is not defined sendobject @index.jsp:15onclick @index.jsp:28
这个问题不是Uncaught ReferenceError: $ is not defined?的重复问题
因为该问题的所有答案都建议首先引用 jquery 脚本,但它对我不起作用。
The right solution was given in tushar's answer
所以这是一个类似的问题,有一个不同的问题和不同的解决方案。
【问题讨论】:
-
您应该检查浏览器中是否已完全加载 jquery 脚本:stackoverflow.com/questions/7486309/…
-
不要更改原始代码。请将其添加为
Edit:或Update: -
@Moradnejad 这个问题不是重复的,我已经更新了。