简体   繁体   中英

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

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:

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

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

在此处输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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