树莓派 - Flask服务器使用JQuery不工作离线(在线工作) [英] Raspberry Pi - Flask Server using JQuery not working Offline (Online it works)

查看:173
本文介绍了树莓派 - Flask服务器使用JQuery不工作离线(在线工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个初学者,我有什么应该是一个容易解决的问题。但是,在研究了很多论坛并尝试了技术解决方案之后,我无法让代码脱机工作,但是它在网上很好地加载了JQuery。我使用Flask创建了一个应用程序,以便使用智能手机应用程序或导航器(Raspberry本地主机)来操作检测机器人。我写了2个代码,Python服务器和HTML客户端。它工作得很好,在线获取JQuery库,如下所示:

< pre class =snippet-code-html lang-html prettyprint-override ; script src =http://code.jquery.com/jquery-1.9.1.min.js>< / script>

现在我想让它脱机工作,我尝试了很多在这个网站的其他问题的解决方案,但我不能让它工作远。
我尝试下载JQuery,并放在相同的文件夹,并在代码中引用它,但没有成功。这是我以为会的。



< script src = jquery-1.9.1.min.jstype =text / javascript>< / script>



我确保把相同的名称和文件夹,尝试子文件夹,有和没有/,但没有任何工作。

目前我也在使用在线css(图片),但是我试着在测试离线JQuery的时候删除它。我只想让JQuery离线工作,这样我就可以完成这个页面。

再次,我是一个新手,所以我很抱歉,提前感谢您的帮助。 / p>

下面是完整的HTML文件,它可以很好的在线工作,它有一些葡萄牙语,但是它们并不重要,因为问题只是在本地加载Jquery。再次感谢您的关注。

< script src =https ://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js>< / script><!doctype html>< html>< head>< meta name =viewportcontent =initial-scale = 1,maximum-scale = 1>< link rel =stylesheethref =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>< ; /头> < style> h3 {text-align:left;} span {font-weight:bold;}< / style>< script type = text / javascript> $(// Ao pressionamento de umbotão,realizar um pedido ajax para o servidor realizando a determinadafunçãofunction(){$('#frente')。click(function(){$ .getJSON('/ _ frente');} ); $('#re')。click(function(){$ .getJSON('/ _re');}); $('#esquerda')。click(function(){$ .getJSON('/ _ esquerda (){$ .getJSON('/ _ direita');}); $('#verticalita')。 ()函数()函数()函数()函数()函数()函数()点击(函数(){$ .getJSON('/ _ azimuteesquerda');}); $('#azimutedireita')。点击(function(){$ .getJSON('/ _ azimutedireita'); }); $('#d')。click(function(){$ .getJSON('/ _ distancia',function(data){$(#distaprox).text(data.distaprox); }); }); }< / script><! - >< body>< < div data-role =header> < div>< h3> ELMO CRSEA IFF< / h3>< / div> < / DIV> < div style =width:400px ;;> <形式> < div id =float1style =width:200px; float:left;> < p为H.;&安培; NBSP; Direcional:其中/ p为H. < p为H.;&安培; NBSP&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP; &安培; NBSP; < button type =buttonname =frenteid =frentestyle =font-size:40px>< i class =fa fa-arrow-up>< / i>< ; /按钮> < / p为H. < p>& nbsp;< p class =buttonname =esquerdaid =esquerdastyle =font-size:40px>< i class =fa fa-arrow-left >< / I>< /按钮> &安培; NBSP&安培; NBSP&安培; NBSP&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP; < button type =buttonname =direitaid =direitastyle =font-size:40px>< i class =fa fa-arrow-right>< / i>< ; /按钮> < / p为H. < p为H.;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP; < button type =buttonname =reid =restyle =font-size:40px>< i class =fa fa-arrow-down>< / i>< ; /按钮> < / p为H. < / DIV> < div id =float2style =200px; float:left;> < p为H.;&安培; NBSP;相机:其中/ p为H. &安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP; < button type =buttonname =verticalcimaid =verticalcimastyle =font-size:40px>< i class =fa fa-toggle-up>< / i><< ; /按钮> < / p为H. < button type =buttonname =azimuteesquerdaid =azimuteesquerdastyle =font-size:40px>< i class =fa fa-toggle-left>< / i>< ; /按钮>  & nbsp;< button type =buttonid =posinitname =posinitstyle =height:50px; width:50px; font-size:15px> Inicial< i< I>< /按钮> & nbsp;< button type =buttonname =azimutedireitaid =azimutedireitastyle =font-size:40px>< i class =fa fa-toggle-right>< / I>< /按钮> < / p为H. < p为H.;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP&安培; NBSP; < button type =buttonname =verticalbaixoid =verticalbaixostyle =font-size:40px>< i class =fa fa-toggle-down>< / i>< ; /按钮>< / p为H. < / DIV> < p为H.;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP; < button type =buttonid =dname =dstyle =height:50px; width:50px; font-size:15px> Medir< i< / i>< / button> Distancia aproximada =< span id =distaprox>< / span> cm< / p> < /形式> < / DIV> <页脚> < p>< h3>版权所有2016 IBL< / h3>< / p> < / footer>< / body>< / html>

尝试创建一个静态文件夹,它将托管所有js和其他静态文件,如下所示:

 

code> static /
- js /
- css /
- ...

现在,将 jquery 文件放在 js / 文件夹中,并在您的

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

在您的模板中,您将拥有:

 < script src ={{url_for('static',filename ='js / jquery-1.9.1.min.js')}}type =text / javascript> ;< /脚本> 


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>

解决方案

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>

这篇关于树莓派 - Flask服务器使用JQuery不工作离线(在线工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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