【问题标题】:want to call python api in my javascript code. I just want to check that how hello world is called from python and printed in javascript想在我的 javascript 代码中调用 python api。我只想检查如何从 python 调用 hello world 并用 javascript 打印
【发布时间】:2017-04-21 10:33:09
【问题描述】:

这是我的 python 代码,我想通过按钮在我的 html 代码页面布局上显示它我只想检查它是如何在 javascript 中调用的。

print("hello world")    (savelist.py)

这是我的 html javascript 文件

<html>`<html>`
<head>
hjgkhkj
</head>`enter code here`
<body>


<input type="text" name="name" id="name">
<button type="button" id="home" onclick="validate()" value="checkvalue">
<script>
$('#id').click(function(){

 $.ajax({
      type:'get',
      url:<YOUR SERVERSIDE PAGE URL>,
      cache:false,
      data:<if any arguments>,
      async:asynchronous,
      dataType:json, //if you want json
      success: function(data) {
        <put your custom validation here using the response from data structure >
      },
      error: function(request, status, error) {
        <put your custom code here to handle the call failure>
      }
   });enter code here
});
</script>
</body>
</html>

【问题讨论】:

    标签: javascript python html ajax api


    【解决方案1】:

    python 文件不会自行返回任何内容。您需要提供一种方法来处理 python 文件中的 Ajax 请求并返回 JSON 响应,如果这就是您所追求的。我不知道您拥有或正在寻找什么样的设置,所以我不知道还有什么建议。

    这是请求文档的链接 -> http://docs.python-requests.org/en/master/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-26
      • 1970-01-01
      • 1970-01-01
      • 2022-12-16
      • 1970-01-01
      • 2018-04-16
      相关资源
      最近更新 更多