从html javascript表单调用python程序

从html javascript表单调用python程序,javascript,python,html,function,command-line,Javascript,Python,Html,Function,Command Line,我试图制作一个网页,在其中输入纬度和经度,python程序将以图形的形式处理纬度和经度。为了简单起见,在这个问题中,我让python程序重复纬度和经度,因为我想知道如何在html和javascript代码的上下文中运行python程序,并将参数从html表单(纬度和经度)传递到python脚本中。以下是html代码: <html> <head> <script> function set_iterations() { var

我试图制作一个网页,在其中输入纬度和经度,python程序将以图形的形式处理纬度和经度。为了简单起见,在这个问题中,我让python程序重复纬度和经度,因为我想知道如何在html和javascript代码的上下文中运行python程序,并将参数从html表单(纬度和经度)传递到python脚本中。以下是html代码:

<html>

<head>

<script>

    function set_iterations()
    {
       var count = 0;
       var lat = document.getElementById("lat").value;
       var lon = document.getElementById("lon").value;
       document.write("latitude is " + lat + " and longitude is " + lon + "</br>"); 
      $.ajax({
         type: "POST"
         url: "testmaker.py" + lat + lon
       });
   }

</script>
</head>

<body>
       <td style='border-right:none' align='center'>Latitude: </td>
       <td style='border-right:none' align='center'><input type=text id='lat' size=10></td>
       <td style='border-right:none' align='center'>Longitude: </td>
       <td style='border-right:none' align='center'><input type=text id='lon', size=10></td>
       <br> 
       <button style="width:200px;margin-top:5px;margin-bottom:20px;"   onClick="set_iterations();">Submit</button>

</body>
</html>
我应该如何修改这个程序,以便表单上的submit按钮调用python程序,表单中的条目是python程序的命令行参数


在ajax调用的参数之间需要一个逗号:

$.ajax({     
    type: "POST",         
    url: "testmaker.py" + lat + lon
});
您需要某种web服务器。首先,您可以在节点中编写一个超级简单的服务器:

server.js
var http = require('http');
var fs = require('fs');
var index = fs.readFileSync('form.html');

http.createServer(function (req, res) {
  console.log("request made") ;
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end(index);
}).listen(9615);
启动它:

node server.js
然后从浏览器转到


现在,您需要在服务器中执行一些操作,以响应对“testmaker”url的调用…

我不相信您可以在没有web服务器的情况下直接从UI调用脚本(例如,对于一个实例,使用nodeJS)。您可以在nodeJS中编写API,然后从那里调用python!确保您的python脚本设置正确,并且能够返回响应。此外,可能的重复:不是完全重复。我还处理命令行参数,而另一篇文章没有处理。您需要添加更多信息,是否遇到控制台错误单击submit按钮时?是否可以导航到此python脚本?脚本的路径是否正确?如何使服务器响应“testmaker.py”调用?
node server.js