未捕获的ReferenceError:$未定义(ajax)

时间:2015-11-10 09:19:29

标签: jquery ajax

我在一个简单的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>
  

未捕获的ReferenceError:$未定义sendobject   @ index.jsp:15onclick @ index.jsp:28

1 个答案:

答案 0 :(得分:11)

<script>不应该是自我关闭的,它不会加载脚本。见Why don't self-closing script tags work?

更改

<script rel="javascript" type="text/javascript" href="js/jquery-1.11.3.min.js"/>

<script rel="javascript" type="text/javascript" href="js/jquery-1.11.3.min.js"></script>