Uncaught ReferenceError:未定义jQuery |从HTML按钮触发python脚本| Google App Engine

问题描述 投票:0回答:1

我目前在Google App Engine上托管一个网站,并且custom.html网页包含一个运行python脚本的按钮。我的错误是单击该按钮会激活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

![enter image description here][1]][1

这是我的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

这是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>

[最后,在进行故障排除时,我从custom.html中删除了<script src="../static/js/app.js"></script>(以防这引起了jquery问题,该问题似乎已经消失了,但是我不确定这是否是原因),但是我仍然收到了另一个在Chrome开发人员工具下出现相同的错误。

enter image description here

非常感谢任何建议和见识。

javascript python jquery referenceerror
1个回答
0
投票

尝试删除:

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

并添加

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

希望有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.