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!
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.
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')}
$.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?
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.
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!")