2010-09-16 129 views
0

我有問題發佈數據到我本地的appengine應用程序使用JQuery Ajax。這裏被簡化客戶端代碼:谷歌Appengine&jQuery:錯誤414(請求的URI太長)

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); 
}); 

這裏被簡化服務器端代碼:

class StoryEdit(webapp.RequestHandler): 
    def post(self): 
     f = Story.get(self.request.get('story_id')) 
     f.html = self.request.get('data') 
     f.put() 

的誤差414(請求URI太長)。我究竟做錯了什麼?

回答

6

請勿使用GET將數據發送到服務器,請改用POST!雖然您使用的是POST,但通過請求參數提交數據,這些數據的大小有限。

嘗試

text_to_save = 'large chunk of html here' 
req = '/story/edit?story_id=' + story_id; 
$.post(req, {data: text_to_save}); 
3

的URI的最大長度的限制。這很大,但是如果你傳遞一串長長的數據,你可能會擊中它。重構您的代碼以將文本作爲後期變量發送。

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); 
}); 

而且

class StoryEdit(webapp.RequestHandler): 
    def post(self): 
     f = Story.get(self.request.post('story_id')) 
     f.html = self.request.post('data') 
     f.put() 

這裏有一些更多的信息:「通常Web服務器設置長度真正的URL相當大方限制例如高達2048或4096個字符」 - http://www.checkupdown.com/status/E414.html

+0

由於某些原因(錯誤或網站規則),我無法接受正確答案,所以謝謝。 – SM79 2010-09-16 12:21:20

相關問題