jquery - 使用 jQuery 在 Google App Engine 中提交 Ajax 表单

标签 jquery python ajax google-app-engine

无法弄清楚为什么它不起作用:

我需要向服务器发送请求,使用 meanCal 方法在 python 中生成一些 html 片段,然后希望将该片段嵌入到使用计算方法提交的 html 文件中,并动态显示在 dyContent div 中。所有过程都是通过单击表单中的提交按钮完成的。

有什么建议吗???提前致谢。

提交html:

<div id="dyContent" style="height: 200px;">
            waiting for user...
            {{ mgs }}   
</div>


<div id="leturetext">
    <form id="mean" method="post" action="/calculation">
        <select name="meanselect">
            <option value=10>example</option>
            <option value=11>exercise</option>
        </select>
        <input type="button" name="btnMean" value="Check Results" />
    </form>
</div>

<script type="text/javascript"> 
$(document).ready(function() { 
  //$("#btnMean").live("click", function() {
  $("#mean").submit(function(){
     $.ajax({
       type: "POST",
       cache: false,
       url: "/meanCal",
       success: function(html) {
         $("#dyContent").html(html);
       }
     });
     return false;
  });
});
</script>

python :

class MainHandler(webapp.RequestHandler):
  def get(self):
    path = self.request.path
    if doRender(self, path):
        return
    doRender(self,'index.htm')

class calculationHandler(webapp.RequestHandler):
  def post(self):
    doRender(self, 'Diagnostic_stats.htm',
{'mgs' : "refreshed.", })

  def get(self):
    doRender(self, 'Diagnostic_stats.htm')



class meanHandler(webapp.RequestHandler):

  def get(self):
    global GL
    index = self.request.get('meanselect'.value)
    if (index == 10):
        allData = GL.exampleData
        dataString = ','.join(map(str, allData))
        dataMean = (str)(stats.lmean(allData))
        doRender(self, 'Result.htm',
        {
        'dataIn' : dataString,
            'MEAN' : "Example Mean is: " + dataMean,
              })
        return
    else:
        allData = GL.exerciseData
        dataString = ','.join(map(str, allData))
        dataMean = (str)(stats.lmean(allData))
            doRender(self, 'Result.htm',
        {
        'dataIn' : dataString,
            'MEAN' : "Exercise Mean is: " + dataMean,
              })



def main():
  global GL
  GL = GlobalVariables()
  application = webapp.WSGIApplication(
        [('/calculation', calculationHandler),
    ('/meanCal', meanHandler),
        ('.*', MainHandler),
        ],
      debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == '__main__':
  main()

最佳答案

要在您的 GAE 应用程序中调试 python 代码,请在正在运行的应用程序上使用应用程序引擎启动器日志:

Using Google App Engine logs

这应该有助于阐明应用程序出现故障的地方。我还建议也对 logging.info(或 logging.debug)进行一些调用。

例如:

import logging
class MainHandler(webapp.RequestHandler):
  def get(self):
    logging.info("Mainhandler has been called.")
    path = self.request.path
    logging.info("Mainhandler called for:" + path)
    if doRender(self, path):
        return
    doRender(self,'index.htm')

关于jquery - 使用 jQuery 在 Google App Engine 中提交 Ajax 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2251505/

相关文章:

javascript - 如何获取ajax响应数组的键以构建数据表头?

javascript - 尝试使用 jquery 使图像旋转

python - 解析 GTF 基因文件

python - Visual Studio Code 看不到 wget

php - 控制台日志显示整个文件而不是数据

javascript - 如何将 Jquery/Ajax 与 asp.net MVC 4 结合使用,并使用部分 View 和模型操作

Python请求登录

javascript - 在新闻提要上重复淡入淡出

javascript - 将 50,000 多个字符的 JSON 字符串解析为 javascript 对象

php - 使用 AJAX 从客户端插入 mySQL