2012-11-17 44 views
2

我只是試圖做一個簡單的ajax調用,點擊一個按鈕,使用ajax從文本框中傳遞一些數據,並在ajax調用後檢索相同的數據。但有些東西是凌亂的在這裏causin警報沒有任何數據在GAE中獲取AJAX調用響應的問題Python

這裏是我的ajaxTest.html

<html> 

    <head> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" 
     type="text/javascript"> 

     </script> 
     <script> 
      function getData() { 
       var vdata = $('#txt').val(); 
       $.ajax({ 
        type: "GET", 
        url: "/processAjax", 
        data: vdata, 
        success: function (responseText) { 
         alert(responseText); 
        } 
       }); 
      } 
     </script> 
    </head> 

    <body> 
     <input id="txt" type="textbox" runat="server" /> 
     <input type="button" runat="server" onclick="getData();" /> 
    </body> 

</html> 

這裏是我的main.py

import httplib2 
import os 

class AjaxCall(webapp.RequestHandler): 
    def get(self): 
    template_data = {} 
    template_path = 'ajaxTest.html' 
    self.response.out.write(template.render(template_path,template_data)) 

class ProcessAjax(webapp.RequestHandler): 
    def get(self): 
    inputdata = self.request.get("inputData") 
    self.response.out.write(inputdata) 


application = webapp.WSGIApplication(
            [('/processAjax',ProcessAjax), 
         ('/ajaxPage',AjaxCall) 
            ], 
            debug=True) 

def main(): 
    run_wsgi_app(application) 

if __name__ == "__main__": 
    main() 

回答

2

你的AJAX調用不包括inputData查詢字段高。更新您的jQuery $.ajax()data參數:

data: { inputData: vdata }, 
+0

喔DAT是一個愚蠢的mistake.Thnks指點出來:) – iJade