使用$ .post有字符限制? [英] using $.post has character limits?

查看:177
本文介绍了使用$ .post有字符限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery $ .post方法将字符串发送到servlet.

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

temp的字符较少(例如5000)时,

testServlet接收到调用.字符,即> 5000不会被调用. Firebug说已中止". 我不明白为什么.

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.

我认为这可能是因为上面的代码以get格式发送了temp,所以我这样写-

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

但是在这种情况下,调用了servlet,但是param为null.
1.两种方法有什么区别?
2.如果第一个方法是get,那么为什么jquery有$ .get?

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 ?

推荐答案

最大URL长度有限制,具体取决于网络浏览器,网络服务器等. 当您传递url中的某些参数时,即使您使用POST请求,参数也会过长.

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.

在您的代码中,只有 {param:temp} 将存储在请求正文中. str 是网址,因此具有最大长度限制.

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

这篇关于使用$ .post有字符限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆