Google Appengine & jQuery: Error 414 (Requested URI too long)
I have problems posting data to my local appengine application using JQuery Ajax. Here is simplified client side code:
text_to_save = 'large chunk of html here'
req = '/story/edit?story_id=' + story_id + '&data=' + text_to_save;
$.post(req, function(data) {
$('.result').html(data);
});
Here is simplified server side code:
class StoryEdit(webapp.RequestHandler):
def post(self):
f = Story.get(self.request.get('stor开发者_开发问答y_id'))
f.html = self.request.get('data')
f.put()
The error is 414 (Requested URI too long). What am I doing wrong?
Don't use GET to send Data to the server, use POST instead! Although you are using POST, the data is submitted via the Request-Parameters, those are limited in size.
Try
text_to_save = 'large chunk of html here'
req = '/story/edit?story_id=' + story_id;
$.post(req, {data: text_to_save});
URI's have a maximum length restriction. It's big, but if you're passing along a long string of data, you might be hitting it. Refactor your code to send the text as a post variable.
text_to_save = 'large chunk of html here'
req = '/story/edit';
$.post(req, { story:id: story_id, data: text_to_save }, function(data) {
$('.result').html(data);
});
And
class StoryEdit(webapp.RequestHandler):
def post(self):
f = Story.get(self.request.post('story_id'))
f.html = self.request.post('data')
f.put()
Here's some more information: "Typically Web servers set fairly generous limits on length for genuine URLs e.g. up to 2048 or 4096 characters" - http://www.checkupdown.com/status/E414.html .
精彩评论