【发布时间】:2017-07-10 10:47:25
【问题描述】:
我在远程服务器上有一个 python 程序。我需要创建一个网页(与服务器上的 python 脚本位于同一目录中的 html 代码)有一个按钮来单击应该运行的 python 脚本。还有一件事是我们需要从本地机器中选择一个文件,然后python脚本将该文件作为输入,运行并输出另一个需要在网页上显示的文件。
我不知道用什么 javascript 或 ajax 或 php 来实现这一点。我尝试了不同的方法但徒劳无功。
这是我一直在尝试的 html 代码...
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
// var file = $('#fileInput')[0].files[0]
var fd = new FormData();
fd.append('fileInput', file);
// console.log(fd)
$.ajax(
{
type: "POST",
url: "./summarize.py",
data: "fd"
success: function (response) {
}
// error: function (response) {}
});
});
});
</script>
</head>
<body>
<h3>Upload reviews file</h3>
<input type="file" id="fileInput" name="fileInput">
<p>Click the "Get summary" button to summarize the reviews.</p>
<button>Get summary</button>
</body>
</html>
我在网上搜索过,但没有具体的答案(我觉得是这样)。由于我是 javascript 新手,因此在关注它们时遇到了麻烦。有人请解释要做什么。
谢谢。
【问题讨论】:
标签: javascript php jquery python html