2

I am working on an MVC 3 project and I have an ajax request ($.ajax) that passes a javascript Array to a controller and returns an HTML result (a partial view with a select element and options).

When the array is 46 items or larger, the call to the controller is not made (I have a break point on the controller and it is not triggered).

I then changed the ajax to request to a $.ajax of type 'POST' and the request runs fine, with all data from he array present.

I have Googled around trying to understand why this may be so but have come up empty, besides this question from stack overflow, which does not help me much, as it speaks generally between the difference between get and post requests - no observable changes on the server (which is what i want) vs changes on server side. I am simply loading data for the user to select from.

Perhaps it is my understanding of ajax get and post requests that is a little fuzzy, but if anyone has ever encountered this kind of issue and understands why, I would very much appreciate the feedback. :)

Below is a sample of the code I am trying to execute:

$(function () {
  $('#SelectedCategory').change(function () {

    //create array of selected attributes to limit returned results set
    var currentAttribs = new Array();
    $('#cboSelectedAttributes option').each(function () {
        currentAttribs.push(this.text);
    });

    //retrieve available attributes from server excluding current selections
    $.ajax({
        url: folder + '/Index_GetAttributes',
        type: "POST",
        data: { strCategory: $(this).find(':selected').val(), lstCurrentAttributes: currentAttribs },
        traditional: true,
        success: function (result) {
            $('#divAvailAAttribs').html(result);
        }
    });
  });
});

Thanks!

Smiley
  • 21
  • 1
  • I am also importing the following libraries: jquery-1.5.1.min.js & modernizr-1.7.min.js – Smiley Apr 19 '13 at 09:58
  • 1
    http://stackoverflow.com/questions/2659952/maximum-length-of-http-get-request read here. – Alexandru Chelariu Apr 19 '13 at 09:58
  • Ah, that makes more sense, especially as to why the post worked instead of the get. I'm still getting the issue with around 44- 46 items in the array, but i suppose all the data is roughly the same size and text length, so it makes some sense. Thanks Alexandru – Smiley Apr 19 '13 at 10:08

1 Answers1

0

Generaly, GET is shorter than POST. Although actual supported size of request data depends on specific server, it is not recommended to have GET requests URI longer than 255 bytes.

I recommend to check with some web debugging tool the lenght of your GET request, you'll know more then.

jan.zanda
  • 146
  • 2