未捕获的ReferenceError:未定义$(ajax) [英] Uncaught ReferenceError: $ is not defined (ajax)

查看:73
本文介绍了未捕获的ReferenceError:未定义$(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


此问题不是>未捕获到的ReferenceError:未定义$吗?

因为该问题的所有答案都建议将对jquery脚本的引用放在首位,但是它对我不起作用.

在tushar的答案中给出了正确的解决方案

因此,这是一个相似问题,其中包含不同的问题不同的解决方案.


解决方案

<script>不应自行关闭,它不会加载脚本.请参见为什么自关闭脚本标签不起作用?

更改

<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>

I have this error on a simple jsp : Uncaught ReferenceError: $ is not defined

I've just try to recall a service rest on another project on eclipse but it seem doesn't work..

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

<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


This question is not a duplicate of 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 .

The right solution was given in tushar's answer

So it's a similar question with a different problem and different solution.


解决方案

<script> should not be self-closed, it'll not load the script. See Why don't self-closing script tags work?

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>

这篇关于未捕获的ReferenceError:未定义$(ajax)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆