python的count变量_如何从python处理程序获取count变量到javascript函数?

我试图以user1、user2、user3等形式向每个新用户发出用户名。在

作为my previous question的结果,现在我明白我需要在应用程序中而不是在浏览器中跟踪计数。所以我创建了/counthandler(我正在使用Google App Engine Python):class CountHandler(webapp.RequestHandler):

def get(self):

count = count + 1

在/choice中,我有以下脚本:

^{pr2}$

如何从/counthandler到{}得到“count”?我知道我需要使用hmlhttpprequest,但不确定如何使用。谢谢。在

更新

关于J00的问题,请致电J00,详细说明:var xhr = new XMLHttpRequest();

xhr.open("POST", "http://localhost:8086/counthandler", true);

xhr.onreadystatechange = function (aEvt) {

if (xhr.readyState == 4 && xhr.status == 200){

console.log("request 200-OK");

}

else {

console.log("connection error");

}

};

//I am not sure what to put in send()?

xhr.send();

更新2

为了回应jfriend00的评论和提供的参考,我将调用改为GET;但不确定之后会发生什么:var xhr = new XMLHttpRequest();

xhr.open("GET", "http://localhost:8086/counthandler", true);

xhr.onreadystatechange = function (aEvt) {

if (xhr.readyState == 4 && xhr.status == 200){

console.log("request 200-OK");

}

else {

console.log("connection error");

}

};

//changed this to "null". this now opens the connection.

//what do I do after this?

xhr.send(null);

更新回答jfriend00的更新答案:

谢谢你的详细解释。现在我明白了。但我还是有一些东西我没有。很容易得到count的值:query = Count.all()

query.get()

count = e.count

logging.info("count = %s" % count)

# gives count = 12

现在你说的是,把python变量“count”的值赋给js变量“count”,它是12

var count = 12;

我不明白的是下次数到13时会发生什么?在

在我看来

var count = count;

不起作用。对的?我错过了什么?在

再次感谢。在

更新以尝试jfriend00答案中的第二个选项。似乎我需要包含一个成功函数来获取/counthandler发送的“count”变量:var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function()

{

if (xhr.readyState == 4 && xhr.status == 200)

{

//get "count" sent by /counthandler?

//var count = count;

}

};

xhr.open("POST", "http://localhost:8086/counthandler", true);

xhr.send(null);

但是我仍然不明白/counthandler如何发送“count”以及如何在success函数中获取它。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值