簡體   English   中英

未捕獲的引用錯誤:未定義 jQuery | 從 HTML 按鈕觸發 python 腳本 | 谷歌應用引擎

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

我目前在 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

![在此處輸入圖像描述][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 的開發人員工具下收到其他相同的錯誤。

在此處輸入圖像描述

非常感謝任何建議和見解。

在此處輸入圖像描述

嘗試刪除:

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

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM