![](/img/trans.png)
[英]How to fix: "Uncaught ReferenceError: loadRecords is not defined" with Google App Script
[英]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
这是我的 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.