2011-12-06 16 views
0

我找不到jQuery + web.py的任何教程。 所以我有關於POST方法的基本問題。如何從jQuery腳本(web.py)獲取數據?

我有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 

我希望看到字符串 「下一步」,在控制檯。但它沒有發生。

我有一種強烈的感覺,即選擇器無法正常工作。任何方式來檢查它?

+3

jQuery.ajax期待一個網址要發佈/獲取內容,請在類型和數據旁邊添加url參數 –

回答

4

你需要使用web.input在web.py訪問POST變量

看看文檔:http://webpy.org/docs/0.3/api(搜索 「功能,輸入」)

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

不幸的是它不起作用 – AlexNasonov

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> 

添加服務器的url。

+0

找到此示例:http://kooneiform.wordpress.com/2010/02/28/python-and-ajax-for-beginners-with- webpy-and-jquery/- 它的工作原理沒有URL。 – AlexNasonov

+0

正如我從jQuery文檔瞭解 - 當前頁面是URL的默認設置,所以我可以忽略此行 – AlexNasonov