3
我正在使用web.py框架來設置我的網站。當我點擊一個按鈕時,我想將數據發送到服務器,然後通過發生器功能/收益率發回數據。基本上可以在數據準備就緒時產生數據,而不是等待我的數據功能完全結束。Web.py |通過POST和AJAX生成數據(生成器函數)
我得到yield to work via GET,但我通過AJAX的POST實現是問題。
def POST(self):
web.header('Content-type','text/html')
web.header('Transfer-Encoding','chunked')
yield "hello"
sleep(10)
yield "hello"
而我的javascript:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#button").click(function() {
jQuery.ajax({
type: "POST",
dataType: "text",
cache: false,
success: function(data){
jQuery("#container").html(data)
}
}); }); });
</script>
輸出:
HelloHello (after 10 seconds)
rather than..
Hello (10 second delay) Hello
注意:我使用內置的服務器我的本地機器上web.py的。