Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
165 views
in Technique[技术] by (71.8m points)

javascript - using $.post has character limits?

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...