Google App Engine + jQuery Ajax = 405 Method not allowed

Someone should be able to explain what I'm doing wrong here! I am trying to create a simple example of publishing AJAX in a Google App Engine application ... and I fail!

Here is a python application


import cgi from google.appengine.api import users from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.ext import db from django.utils import simplejson class EmailItem(db.Model): email = db.StringProperty(multiline=False) date = db.DateTimeProperty(auto_now_add=True) class EmailList(webapp.RequestHandler): def get(self): self.response.out.write("You see nothing!") def post(self): eitem = EmailItem() eitem.email = self.request.get("address") eitem.put() self.response.out.write("success") application = webapp.WSGIApplication([('/', EmailList)]) def main(): run_wsgi_app(application) if __name__ == "__main__": main() 

And here is jQuery


 $.ajax({ type: "POST", url: "myappengineURL", data: "address=" + sVerifiedEmail, success: function(msg) { alert("Data Saved: " + msg); }, }); 

Assuming I really know how to use jQuery and call an AJAX call ... why do I keep getting 405 error?

I rewrote this thing in six different ways, trying to get it to work ... and I can't! So far I’m watching advice from http://blog.pythoughts.com/posts/AJAX-with-Google-App-Engine#jqueryAjax and the Google AJAX RPC article in which I cannot post the link because StackOverflow says NO NO NO. None of these examples work for me.

What am I doing wrong?

+4
source share
6 answers

Your problem is known as "the same origin policy." This is why you see the OPTIONS method in your log. The domain and protocol of your Ajax request should be the same as the one from which you start it.

Here is the same question with good answers.

+5
source

I have included jQuery in the AJAX example for the Google App Engine . Replace their doAdd () and custom javascript AJAX with:

 <script language="javascript" src="./static/jquery.js"></script> <script language="javascript" src="./static/json2.js"></script> <script language="javascript"> function doAdd() // Requests server to add two numbers, loads server response to result { $.get( '/rpc', {"action" : "Add", "arg0" : JSON.stringify($("#num1").val()), "arg1" : JSON.stringify($("#num2").val())}, function(response) { $('#result').val(JSON.parse(response)); } ); } </script> 

It works for me! Hope this helps.

+3
source
 $.ajax({ type: "POST", url: "myappengineURL", data: ({address : sVerifiedEmail}), success: function(msg) { alert("Data Saved: " + msg); }, }); 

What happens when you structure your challenge, as I am above?

0
source
  • Check your logs in App Engine. What is the method and what is the URL?
  • Try POST using Curl or Wget. It works?
0
source

Instead: application = webapp.WSGIApplication ([('/', EmailList)])

try: application = webapp.WSGIApplication ([('. *', EmailList)])

Also, shouldn't the data parameter in JS be a dictionary? like: var data = {'email': $ F ('email_field_name')}

0
source

All the other answers were stupid.

You need mail, not get. That should say:

 class EmailList(webapp.RequestHandler): def post(self): self.response.out.write("You see nothing!") 
-1
source

All Articles