使用 $.getJSON 时是否有字符串长度限制?
所以我有这个 javascript 作为我的调用:
$("#addNewThankYou").click(function () {
var thankYouNote = $("#thankYouNote").html();
var name = $("#enteredName").html();
$.getJSON("/Home/AddEntryToDatabase", { Name: name, ThankYouNote: thankYouNote }, function (data) {
...
});
});
后面的 C# 方法非常标准:
public ActionResult AddEntryToDatabase(String Name, String ThankYouNote){
...
}
我的问题可能在于传入的字符串的长度。例如,如果我传入一个很小的名称和注释(< 100字符)我没有任何问题,它可以很好地触发该方法。但是,如果我有一个很长的注释,它根本不会触发该方法;当我单击调用 addNewThankYou.click 的按钮时,它没有执行任何操作。我尝试在被调用方法的第一行放置一个断点,但它根本没有进入。
所以,我的问题是这样的。我可以通过 getJSON jQuery 方法传递的字符串大小是否有限制?如果是这样,关于如何解决这个问题有什么建议吗?我不想将这些感谢信限制在 100 个字符以内!
So I have this javascript as my call:
$("#addNewThankYou").click(function () {
var thankYouNote = $("#thankYouNote").html();
var name = $("#enteredName").html();
$.getJSON("/Home/AddEntryToDatabase", { Name: name, ThankYouNote: thankYouNote }, function (data) {
...
});
});
The C# method behind is pretty standard:
public ActionResult AddEntryToDatabase(String Name, String ThankYouNote){
...
}
My problem lies potentially in the length of the string being passed in. For example, if I pass in a name and a note that are small (< 100 characters) I dont have any issues, it fires the method just fine. However, if I have a note that is pretty long, it doesn't fire the method at all; when I click the button that calls the addNewThankYou.click is doesnt do anything. I tried putting a breakpoint on the first line of the method that gets called, and it doesn't go in at all.
So, my question is this. Is there a limit to the string size that I can pass through the getJSON jQuery method? If so, any suggestions on how to get around this? I dont want to limit these thank you notes to 100 characters!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从历史上看,您始终需要谨慎处理长查询字符串(即 GET 请求)。在过去的日子里,我相信查询字符串的长度受到限制。如果您发送大量数据而使用 ajax - POST 可能会更好。
Historically you've always needed to treat long query strings (ie GET requests) with caution. In days gone by I believe query strings were restricted in length. It would probably be better if you were sending a large amount of data to use a ajax - POST instead.
这张 SO 票可能对您有用:
浏览器响应大小限制
基本上,它解释了 IE 和 FF 对数据都有限制(两者GET 和 POST 方法)。因此,很长的数据可能会导致它无法触发。即使您不使用 IE 或 FF,您可以处理的数据量也可能存在一些限制。
This SO ticket might be of some use to you:
Browser response size limit
Basically, it explains that both IE and FF have limits on data (with both the GET and POST methods). So, really long data could be causing it to not fire. Even if you aren't using IE or FF, there are probably some limitations on the amount of data you can process.
GET 请求将所有参数放在 URL 中。因此,如果不出意外,您需要了解浏览器对其处理的 URL 长度设置的限制。一般来说,您不能假设您可以在整个 URL 中发送超过 2000 个字符。
http - URL 的最大长度是多少
A GET request places all of the parameters in the URL. So if nothing else, you need to know what limits the browsers place on the length of URL they'll handle. Generally, you can't assume you can send more than ~2000 characters in the URL as a whole.
http - What is the maximum length of a URL