1

I'm a beginner and I have what should be an easy problem to solve. However, after researching many forums and trying the technical solution, I could not make the code to work offline, but it does work just fine loading JQuery online. Let me start explaining my work so far.

I used Flask to create an application so I could manipulate an inspection robot using smartphone app or navigator (Raspberry local host). I wrote 2 codes, the Python server and HTML client. It works just fine online, getting the JQuery library as it follows:

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

Now I want to make it to work offline and I tried many solutions given in other questions in this website, but I just could not make it work so far. I tried downloading the JQuery and placing in the same folder and referencing it in the code with no success. This is what I thought it would be.

<script src="jquery-1.9.1.min.js" type="text/javascript"></script>

I made sure to put the same name and folder, tried subfolder, with and without the "/", but nothing is working.

For the moment I`m using also online css (for images), but i tried removing it too while I was testing the offline JQuery. I just wanna get JQuery to work offline so I can finish the page.

Again, I`m a newbie, so I apologize and thank you in advance for your help.

Here is the full HTML file that does work just fine online, it has some portuguese but they don`t matter since the problem is just loading Jquery locally. Again, thank you for the attention.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<!doctype html>
<html>
<head>
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head> 

<style>
h3 {text-align: left;}
span {font-weight: bold;}
</style>

<script type=text/javascript>
    $(
    // Ao pressionamento de um botão, realizar um pedido ajax para o servidor realizando a determinada função
    function() 
    {
        $('#frente').click(function() 
        {
        $.getJSON('/_frente');
        }); 
 $('#re').click(function() 
        {
        $.getJSON('/_re');
        });
 $('#esquerda').click(function() 
        {
        $.getJSON('/_esquerda');
        });
 $('#direita').click(function() 
        {
        $.getJSON('/_direita');
        });
 $('#verticalcima').click(function() 
        {
        $.getJSON('/_verticalcima');
        });
 $('#verticalbaixo').click(function() 
        {
        $.getJSON('/_verticalbaixo');
        }); 
 $('#posinit').click(function() 
        {
        $.getJSON('/_posinit');
        }); 
 $('#azimuteesquerda').click(function() 
        {
        $.getJSON('/_azimuteesquerda');
        }); 
 $('#azimutedireita').click(function() 
        {
        $.getJSON('/_azimutedireita');
        }); 
        $('#d').click(function() 
        {
        $.getJSON('/_distancia', function(data)
            {
                $("#distaprox").text(data.distaprox);
            });
        });
        
    }
    );

</script>
<!-- Uma simples pagina JQuery Mobile para realizar o controle remoto do sistema robotico de inspeção -->

<body>
  <div data-role="header">
    <div><h3>ELMO CRSEA IFF</h3></div>
  </div>
  <div style="width:400px;;">
    <form>
    <div id="float1" style="width:200px;float:left;">
    <p>&nbsp;Direcional:</p>
    <p>&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button type="button" name="frente" id="frente" style="font-size:40px"><i class="fa fa-arrow-up"></i></button>
    </p>
    <p>&nbsp;<button type="button" name="esquerda" id="esquerda" style="font-size:40px"><i class="fa fa-arrow-left"></i></button>
    &nbsp&nbsp&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button type="button" name="direita" id="direita" style="font-size:40px"><i class="fa fa-arrow-right"></i></button>
    </p> 
    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button type="button" name="re" id="re" style="font-size:40px"><i class="fa fa-arrow-down"></i></button>
    </p>
    </div>
    <div id="float2" style="200px;float:left;">
    <p>&nbsp;Câmera:</p>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button type="button" name="verticalcima" id="verticalcima" style="font-size:40px"><i class="fa fa-toggle-up"></i></button>
    </p>
    <button type="button" name="azimuteesquerda" id="azimuteesquerda" style="font-size:40px"><i class="fa fa-toggle-left"></i></button>
    &nbsp;&nbsp;<button type="button" id="posinit" name="posinit" style="height:50px;width:50px;font-size:15px">Inicial<i</i></button>
    &nbsp;<button type="button" name="azimutedireita" id="azimutedireita" style="font-size:40px"><i class="fa fa-toggle-right"></i></button>
    </p>
    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;
    <button type="button" name="verticalbaixo" id="verticalbaixo" style="font-size:40px"><i class="fa fa-toggle-down"></i></button></p>
    </div>
    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button type="button" id="d" name="d" style="height:50px;width:50px;font-size:15px">Medir<i</i></button> 
    Distância aproximada = <span id="distaprox"></span>cm</p>
    </form>
  </div>

  <footer>
    <p><h3>Copyright 2016 IBL</h3></p>
  </footer>
</body>
</html>
ettanany
  • 19,038
  • 9
  • 47
  • 63

1 Answers1

2

Try to create a static folder that will host all your js and other static files like below:

static/
     - js/
     - css/
     - ...

Now, put your jquery file in js/ folder and use the following in your template:

url_for('static', filename='js/jquery-1.9.1.min.js')

In your template, you will have:

<script src="{{ url_for('static', filename='js/jquery-1.9.1.min.js') }}" type="text/javascript"></script>
ettanany
  • 19,038
  • 9
  • 47
  • 63