如何从jQuery脚本获取数据(web.py)?

0 投票
2 回答
3550 浏览
提问于 2025-04-17 07:48

我找不到关于 jQuery 和 web.py 的任何教程。

所以我有一个关于 POST 方法的基本问题。

我有一个 jQuery 脚本:

<script>
     jQuery('#continue').click(function() {
         var command = jQuery('#continue').attr('value');
         jQuery.ajax({
              type: "POST",
              data: {signal : command},
         });
     });
</script>

还有一个简单的表单:

<form>
    <button type="submit">Cancel</button>
    <button type="submit" id="continue" value="next">Continue</button>
</form>

以及一个 Python 脚本:

def POST (self):
        s = signal
        print s
        return

我希望在控制台看到字符串 "next"。但是没有出现。

我感觉选择器可能有问题。有没有办法检查一下?

2 个回答

0
<script>
     jQuery('#continue').click(function() {
         var command = jQuery('#continue').attr('value');
         jQuery.ajax({
              type: "POST",
              data: {signal : command},
              url: "add the url here"
         });
     });
</script>

添加服务器的地址。

4

你需要在web.py中使用web.input来获取POST请求中的变量。

可以查看文档:http://webpy.org/docs/0.3/api(搜索“function input”)

def POST(self):
    s = web.input().signal
    print s
    return

撰写回答