Reputation: 1351
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!
Upvotes: 4
Views: 4297
Reputation: 239764
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
Upvotes: 1
Reputation: 4226
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.
Upvotes: 1
Reputation: 3954
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.
Upvotes: 1