我是一个初学者,我有一个应该很容易解决的问题。然而,在研究了很多论坛并尝试了技术解决方案之后,我无法使代码离线工作,但它可以很好地在线加载 JQuery。让我开始解释到目前为止我的工作。
我使用 Flask 创建了一个应用程序,这样我就可以使用智能手机应用程序或导航器(Raspberry 本地主机)来操纵检查机器人。我写了 2 个代码,Python 服务器和 HTML 客户端。它在线工作得很好,获取 JQuery 库如下:
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
现在我想让它离线工作,我尝试了本网站其他问题中给出的许多解决方案,但到目前为止我还无法使其工作。 我尝试下载 JQuery 并将其放在同一文件夹中并在代码中引用它,但没有成功。这就是我所想的。
<script src="jquery-1.9.1.min.js" type="text/javascript"></script>
我确保使用相同的名称和文件夹,尝试了子文件夹,带或不带“/”,但没有任何效果。
目前我也在使用在线 css(用于图像),但在测试离线 JQuery 时我也尝试删除它。我只是想让 JQuery 离线工作,这样我就可以完成页面。
再次,我是新手,所以我很抱歉并提前感谢您的帮助。
这里是完整的 HTML 文件,可以在网上正常工作,它有一些葡萄牙语,但它们并不重要,因为问题只是在本地加载 Jquery。再次感谢您的关注。
<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> Direcional:</p>
<p> 
<button type="button" name="frente" id="frente" style="font-size:40px"><i class="fa fa-arrow-up"></i></button>
</p>
<p> <button type="button" name="esquerda" id="esquerda" style="font-size:40px"><i class="fa fa-arrow-left"></i></button>
   
<button type="button" name="direita" id="direita" style="font-size:40px"><i class="fa fa-arrow-right"></i></button>
</p>
<p>
<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> Câmera:</p>
<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>
<button type="button" id="posinit" name="posinit" style="height:50px;width:50px;font-size:15px">Inicial<i</i></button>
<button type="button" name="azimutedireita" id="azimutedireita" style="font-size:40px"><i class="fa fa-toggle-right"></i></button>
</p>
<p>  
<button type="button" name="verticalbaixo" id="verticalbaixo" style="font-size:40px"><i class="fa fa-toggle-down"></i></button></p>
</div>
<p>
<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>
最佳答案
尝试创建一个静态文件夹来托管所有 js 和其他静态文件,如下所示:
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"></script>
关于jquery - Raspberry Pi - 使用 JQuery 的 Flask 服务器无法离线工作(在线工作),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41103458/