简体   繁体   English

未捕获的引用错误:未定义 jQuery | 从 HTML 按钮触发 python 脚本 | 谷歌应用引擎

[英]Uncaught ReferenceError: jQuery is not defined | Trigger python script from HTML button | Google App Engine

I am currently hosting a website on Google App Engine, and the custom.html web-page includes a button that run a python script.我目前在 Google App Engine 上托管一个网站,custom.html 网页包含一个运行 python 脚本的按钮。 My error is clicking that button activates the python script, but my page has the error Uncaught ReferenceError: jQuery is not defined and clicking the button throws Failed to load resource: the server responded with a status of 404 () and a 404 GET error:我的错误是单击该按钮会激活 python 脚本,但我的页面有错误Uncaught ReferenceError: jQuery is not defined并且单击按钮会引发Failed to load resource: the server responded with a status of 404 ()404 GET错误:

send    @   jquery-3.4.1.min.js:2
ajax    @   jquery-3.4.1.min.js:2
goPython    @   custom.html:61
onclick @   custom.html:55

![在此处输入图像描述][1]][1

Here is my app.js script where the error is coming from:这是我的 app.js 脚本,错误来自:

(function($){
  $(function(){

    $('.slider').slider();
    $('.carousel').carousel();
    $('.fixed-action-btn').floatingActionButton();
    $('.tooltipped').tooltip();
    $('.materialboxed').materialbox();

    let tooltipInstances;

    window.onload = function() {
      M.FloatingActionButton.init(document.querySelectorAll('.fixed-action-btn'));
      tooltipInstances = M.Tooltip.init(document.querySelectorAll('.tooltipped'));

      // You should remove this event listener when it is no longer needed.
      window.addEventListener('scroll', () => {
        for (let i = 0; i < tooltipInstances.length; ++i) {
          tooltipInstances[i]._positionTooltip();
        }
      });
    }

  }); // end of document ready
})(jQuery); // end of jQuery name space

And here is the custom.html page that includes the button:这是包含按钮的 custom.html 页面:

<<!DOCTYPE html>
  <html lang="en" dir="ltr">

  <head>
    <meta charset="utf-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="../static/css/style.css">
  </head>

  <body>
    <script src="../static/js/app.js"></script>

    <!-- Content -->

        <button style="text-align: center; margin-bottom: 150px" class="search-btn" type="button" value=" Run Script " onclick="goPython()">Do Something
          <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha384-vk5WoKIaW/vJyUAd9n/wmopsmNhiy+L2Z+SBxGYnUkunIxVxAv/UtMOhba/xskxh" crossorigin="anonymous"></script>

          <script>
            function goPython() {
              $.ajax({
                url: "../Python/main.py",
                context: document.body
              }).done(function() {
                alert('finished python script');;
              });
            }
          </script>
        </button>
      </div>
    </div>
  </body>

  </html>

Lastly, while troubleshooting, I removed <script src="../static/js/app.js"></script> from custom.html (in case this was causing the jquery issue, which seems to have disappeared but I'm not sure if this was the cause), but I still receive the other same errors under Chrome's developer tools.最后,在进行故障排除时,我从 custom.html 中删除了<script src="../static/js/app.js"></script> (以防这导致 jquery 问题,这似乎已经消失了,但我我不确定这是否是原因),但我仍然在 Chrome 的开发人员工具下收到其他相同的错误。

在此处输入图像描述

Any advice and insight is greatly appreciated.非常感谢任何建议和见解。

在此处输入图像描述

Try removing:尝试删除:

<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha384-vk5WoKIaW/vJyUAd9n/wmopsmNhiy+L2Z+SBxGYnUkunIxVxAv/UtMOhba/xskxh" crossorigin="anonymous"></script>

And add并添加

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        </head>

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM