jQuery 未捕获的 ReferenceError: $ is not defined (ajax)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33626519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught ReferenceError: $ is not defined (ajax)
提问by Dwhitz
I have this error on a simple jsp : Uncaught ReferenceError: $ is not defined
我在一个简单的 jsp 上遇到了这个错误:未捕获的 ReferenceError: $ is not defined
I've just try to recall a service rest on another project on eclipse but it seem doesn't work..
我只是尝试在 eclipse 上回忆另一个项目上的服务休息,但它似乎不起作用..
Code is here :
代码在这里:
<!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>
Update:
更新:
Tried using the jQuery from Google CDN, but still doesn't work
尝试使用 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
未捕获的 ReferenceError: $ is not defined sendobject @index.jsp:15onclick @index.jsp:28
This question is not a duplicate of Uncaught ReferenceError: $ is not defined?
这个问题不是Uncaught ReferenceError: $ is not defined?
Because all the answer of that question suggest to put the references to the jquery scripts first, but it does not work for me.
因为该问题的所有答案都建议首先引用 jquery 脚本,但这对我不起作用。
The right solution was given in tushar's answer
So it's a similarquestion with a different problemand different solution.
所以这是一个类似的问题,有不同的问题和不同的解决方案。
回答by Tushar
<script>
should not be self-closed, it'll not load the script. See Why don't self-closing script tags work?
<script>
不应该自我关闭,它不会加载脚本。请参阅为什么自关闭脚本标签不起作用?
Change
改变
<script rel="javascript" type="text/javascript" href="js/jquery-1.11.3.min.js"/>
to
到
<script rel="javascript" type="text/javascript" href="js/jquery-1.11.3.min.js"></script>