Google App Engine 和 Ajax:开机自检时出现错误代码 405



有人可以帮助我解决这个问题吗?当我点击 POST 时,返回的数据应该更新内容div。但我总是收到"405方法不允许"错误消息。

main.py:

# -*- coding: utf-8 -*-
#!/usr/bin/env python2.7
import webapp2
import os
from google.appengine.ext.webapp import template
class Main(webapp2.RequestHandler):
    def get(self):
        render(self, 'base.html', {})
class Form(webapp2.RequestHandler):
    def get(self):
        render(self, 'form.html', {'name': 'get'})
    def post(self):
        render(self, 'form.html', {'name': 'post'})
def render(handler, infile, template_values):
    path = os.path.join(os.path.dirname(__file__), 'templates/', infile)
    handler.response.out.write(template.render(path, template_values))
app = webapp2.WSGIApplication([
    ("/form", Form),
    ("/.*", Main)],
    debug=True)

基.html:

...
<body>
<div id="content">
{% include "form.html" %}
</div>
<script>
function submitForm() {
    $.ajax({
        type: "POST",
        url: $(this).attr('action'),
        data: $(this).serialize(),
        cache: false,
        success: function(returnData){
            $("#content").html(returnData);
        }
    });
}
</script>
</body></html>

形式.html:

<form  id="submitForm" action="/form" enctype="multipart/form-data">
  name: <input type="text" name="abcd" />{{ name }}<br /><br />
      <input type="button" value="Submit" onclick="return submitForm()" />
</form>

问题已解决:只需将 $(this) 更改为 $('#submitForm)

相关内容

最新更新