Search code examples
javascriptjqueryreferenceerror

Jquery reference error


Hey Guys i want to use jquery local because my app doesnt have access to the internet. When i use the jquery google source my code works but with my source local i get a reference error.

jquery-3.1.1.min.js:1 Uncaught SyntaxError: Unexpected token < (index):51 Uncaught ReferenceError: $ is not defined

If you could help me i would be really thankful. I already tried to use the source without port or ip but that also didnt work.

Here is my Code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Socket.io</title>
<script src="/socket.io/socket.io.js"></script>
<script language="JavaScript" type="text/javascript" src="http://192.168.42.1:8080/home/pi/myNode/jquery-3.1.1.min.js"></script>
</head>

<body>
    <h1>Communicating with socket.io!</h1>

<table>
  <tr>
    <td>Geschwindigkeit</td>
    <td>Neigung</td>
  </tr>
  <tr>
    <td><input type="text" name="geschwindigkeit" id="v"></td>
    <td><input type="text" name="Neigung" id="acc"></td>
  </tr>
</table>

 <p> </p>
 <table>
 <tr>
<td><input type="button" value="Move" id="move" /></td>
<td><input type="button" value="Enable" id="enable" /></td>
<td><input type="button" value="test" id="test" /></td>
  </tr>
  <tr>
<td><input type="button" value="Stop" id="stop" /></td>
<td><input type="button" value="Ping" id="ping" /></td>
<td><input type="button" value="Disable" id="disable" /></td>
   </tr>
   </table>

    <script>
       var socket = io.connect();


        // A dialog box is displayed when the server sends us a "message"
        socket.on('message', function(message) {
            alert('Nachricht: ' + message);
        })
 // When the button is clicked, a "message" is sent to the server
        $('#enable').click(function () {
            socket.emit('enable', 'disable');
        })

        $('#disable').click(function () {
            socket.emit('disable', 'disable');
        })

             $('#test').click(function () {
            socket.emit('message', 'test');
        })

        $('#move').click(function () {
              var geschw = document.getElementById("v").value;
      var neig = document.getElementById("acc").value;
      var cmd = new String( "m " + geschw + "    " + neig)
                  socket.emit('move', cmd);
        })

        $('#stop').click(function () {
            socket.emit('stop', 'Car stopped');
        })

        $('#ping').click(function () {
            socket.emit('poke', 'Hallo');
        })


    </script>
    <p></p>
    "<img src='http:192.168.178.51:8077/?action=stream' width='320' height='240'>
</body>


Solution

  • Link to jQuery locally.

    Download the file, then place it in the same directory as you index file. Or anywhere else, but link to it appropriately. E.g. libs/js/jquery/jquery-3.1.1.min.js

    Link to it like this:

    <head>
    <meta charset="utf-8" />
    <title>Socket.io</title>
    <script language="JavaScript" type="text/javascript" src="jquery-3.1.1.min.js"></script>
    <script src="/socket.io/socket.io.js"></script>