如何从python回复并在浏览器中显示它?
问题描述:
我使用.post()
来查询python函数中设备的状态。当它是done
时,它应该返回python函数的返回值。我的Python文件的如何从python回复并在浏览器中显示它?
$.post('/request', {inputText: fbNum,key_pressed: fbType.toString()}).done(function (reply) {
if (reply ^= "count") {
$('#status_table tr #'+eachStatus).empty().append(the-reply-value-here);
} });
部分:
elif "C?" in response[0]:
status="Count= %sH"%response[0].strip()[-2:]
return status
我怎么能获取和显示状态? 我在jquery中使用.get
吗?但我不确定格式。它是
$.get("/request", reply).done(function(data){
$('#status_table tr #'+eachStatus).empty().append(the-reply-value-here);});
?? ??我的回复是Count = FF
。我想要显示的只是FF
。我应该怎么做?
答
尝试
$.post('/request', {inputText: fbNum,key_pressed: fbType.toString()}).done(function (reply) {
if (/^Count\s*=/.test(reply)) {
$('#status_table tr #'+eachStatus).empty().append(reply.replace(/Count\s*=\s*/, ''));
}
});
感谢您的答复。 +1 :)照顾解释'(/^Count \ s * = /。test(reply))'是什么意思?那么'reply.replace()'部分呢? – yvonnezoe 2013-05-07 03:32:03
'/^Count \ s * = /。test'是一个正则表达式,用于测试回复是否以'Count ='开头,然后是[替换](https://developer.mozilla.org/en/docs/ JavaScript/Reference/Global_Objects/String/replace)函数用于替换“Count =”,您可以将空字符串替换为“FF”,如我看到的值 – 2013-05-07 03:35:33
。在那里我可以阅读更多关于这个/ \ * *。句法? :这对我来说有点困惑。所以'/ .test'只是一个随机的名字? – yvonnezoe 2013-05-07 03:39:40