运行带有 Ajax 问题的 Python



我想在我正在构建的Electron应用程序中的按钮的"点击"事件上运行一个Python脚本。

我已经在我正在构建的mainWindow.html页面中包含以下代码来实现此目的:

<script src="https://code.jquery.com/jquery-latest.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script>
// Run Upload
function runUpload(){
$.ajax({
url: "script_1_upload_to_drive.py",
context: document.body
}).done(function() {
alert('Finished Python Script');;
});
};
</script>

我得到的错误如下:

TypeError: $.ajax is not a function

我已经环顾四周,似乎公共区域是人们不小心使用了 JQuery 的苗条版本。我尝试了以下版本,但没有任何改变错误:
https://code.jquery.com/jquery-latest.min.js http://code.jquery.com/jquery-3.3.1.min.js
https://code.jquery.com/jquery-3.2.1.min.js

你可以试试这个:

<script src="https://code.jquery.com/jquery-3.4.0.min.js" integrity="sha256-BJeo0qm959uMBGb65z40ejJYGSgR7REI4+CW1fNKwOg=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-migrate-3.0.1.min.js" integrity="sha256-F0O1TmEa4I8N24nY0bya59eP6svWcshqX1uzwaWC4F4=" crossorigin="anonymous"></script>

并使用事件侦听器来确保文档已加载:

window.addEventListener("load", function(event) {
// The document load is finished, $ should be defined
// Do what you want here
});

最新更新