Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught ReferenceError: $ is not defined (ajax)

Tags:

jquery

ajax

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.


like image 527
Dwhitz Avatar asked Nov 10 '15 09:11

Dwhitz


Video Answer


1 Answers

<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>
like image 108
Tushar Avatar answered Oct 14 '22 00:10

Tushar