views:

58

answers:

2

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('story_id'))
        f.html = self.request.get('data')
        f.put()

The error is 414 (Requested URI too long). What am I doing wrong?

+6  A: 

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});
theomega
+2  A: 

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 .

BBonifield
I can't accept the correct answer for some reason(bug or site rule), so thank you.
SM79
Can someone explain why I was down-voted? This was marked as the accepted answer with 2 up-votes as well.
BBonifield