Google App Engine + jQuery Ajax = 405 Method Not Allowed

前端 未结 6 1115
栀梦
栀梦 2021-01-14 02:14

Someone has to be able to explain what I\'m doing wrong here! I\'m trying to create the MOST simple example of an AJAX post to a Google App Engine app...and I\'m failing!

相关标签:
6条回答
  • 2021-01-14 02:23

    I've incorporated jQuery into the Google App Engine AJAX example. Replace their doAdd() and custom AJAX javascript 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>
    

    Works for me! Hope it helps.

    0 讨论(0)
  • 2021-01-14 02:26

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

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

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

    0 讨论(0)
  • 2021-01-14 02:38
    $.ajax({
            type: "POST",
            url: "myappengineURL",
            data: ({address : sVerifiedEmail}),
            success: function(msg) {
                    alert("Data Saved: " + msg);
            },
        });
    

    What happens when you structure your call like I have above?

    0 讨论(0)
  • 2021-01-14 02:43

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

    Here's the same question with good answers.

    0 讨论(0)
  • 2021-01-14 02:45
    • Check your logs on App Engine. What method is being specified, and what's the URL?
    • Try a POST with Curl or Wget. Does that work?
    0 讨论(0)
  • 2021-01-14 02:45

    All the other answers were stupid.

    You want post instead of get. That should say:

    class EmailList(webapp.RequestHandler):
      def post(self):   
        self.response.out.write("You see nothing!")
    
    0 讨论(0)
提交回复
热议问题