using $.post has character limits?

大憨熊 提交于 2019-12-25 18:28:11

问题


I am using jquery $.post method to send a string to a servlet.

var temp = "hsad d jad a....sad";
var str="testServlet?param="+temp;
$.post(str, function(data) {
    alert("saved");
});

testServlet receives a call when the temp has less characters, say 5000. But when it has more no. of characters i.e. > 5000 it is not called. Firebug says 'Aborted'. I could not understand why.

I thought that this might be because the above code is sending temp in the get form so I wrote like this -

var temp = "hsad d jad a....sad";
var str="testServlet";
$.post(str, {param:temp}, function(data) {
    alert("saved");
});

But in this case the servlet was called but param was null.
1. Is there any difference between the above two methods ?
2. If first method is get then why jquery has $.get ?


回答1:


There are limitations on maximum URL length, depends on web browser, webserver e.t.c. When your pass some parameters in url will have problem with too long parameters even if your use POST request.

In your code only {param:temp} will be stored in request body. str is url so it's has max length restriction.



来源:https://stackoverflow.com/questions/10634712/using-post-has-character-limits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!