Search code examples
jqueryasp.netjqgridwebmethod

jqgrid return error 404 when pass long parameter


Well, jqgrid in my form work normally when my parameter in get method is short.
But when my parameter is so long

  • about 4850 character
  • it returns error 404 not found and my webmethod not fire.
  • as I know there is no limitation on query string legnth.
  • Is there any limitaion on query string?
  • Is there any solution for this problem?

thanks and sorry for my bad english
EDIT
this is my code:

jQuery("#jqGridReport").jqGrid({
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
direction: 'rtl',
url: 'Handler/BrnTotal.ashx',
datatype: "local",
colNames: ['blah','blah','blah'],
colModel: ['blah','blah','blah',],
        rowNum: 50,
        mtype: 'POST',
        loadonce: true,
        pager: '#jqGridReportPager',
        sortname: 'BRName',
        viewrecords: false,
        pgtext: null,
        sortorder: 'desc',
        caption: "شعب",
        hidegrid: false,
        scrollOffset: 0,
        autowidth: true,
        altRows: true,
        altclass: 'myAltRowClass'
    });
    jQuery("#jqGridReport").jqGrid('navGrid', '#jqGridReportPager', { edit: false, add: false, del: false });
    jQuery("#jqGridReport").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn" });


the grid is empty at first.when user select parameter and submit button,this method will run

branchlist = idsel.join(",");
        selectedBrnWork = $('#hiddenField').val();
        startDate = $("#txtStartDate").val();
        endDate = $("#txtEndDate").val();
        $("#jqGridReport").jqGrid('setGridHeight', 'auto');
        var newurl = 'Handler/BrnTotal.ashx?startDate=' + startDate + "&endDate=" + endDate + "&brlist=" + branchlist + "&selectedBrnWork=" + selectedBrnWork;
        $("#jqGridReport").jqGrid('setGridParam', { url: newurl });
        $("#jqGridReport").jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
        $("#element_to_pop_up").bPopup().close();


This is request header when it works:

POST /Handler/BrnTotal.ashx?startDate=1394/05/26&endDate=1394/05/26&brlist=32,50,61&selectedBrnWork=1 HTTP/1.1

and this is when it doesnt work:

POST /Handler/BrnTotal.ashx?startDate=1394/05/26&endDate=1394/05/26&brlist=32,50,61,73,84,92,103,148,149,160...,...,...,2113,2114,2115,2116,2117,2118,2119,2120,2121,2122,2123,2124,2125,2124,2175,2176,2177,2178,2179,2180,2181,2182,2183&selectedBrnWork=1 HTTP/1.1


I short brlist because it is so long


Solution

  • The problem seems to me independent from jqGrid. If you need to send many (or long) parameters to WebMethod the you should use HTTP POST instead of HTTP GET, because the parameters of GET request will be appended to the URL. There are limitations of URL size. The exact maximal length of URL depends on the web browser which you use. Safe limit is about 2000 characters (see the answer for example).

    Thus I would recommend you to use mtype: "POST" instead of default mtype: "GET" used by jqGrid if no mtype is specified.

    UPDATED: You send parameters in the wrong way. The posted code just add parameters startDate, endDate, brlist explicitly to URL. It's wrong. The data should be send in the body of the POST request. You should use postData parameter of jqGrid for it. I would recommend you to use postData in function form:

    url: 'Handler/BrnTotal.ashx',
    datatype: "json",
    mtype: 'POST',
    postData: {
        startDate: function () { return $("#txtStartDate").val(); },
        endDate: function () { return $("#txtEndDate").val(); },
        brlist: function () {
            var idsel = jQuery("#jqGridReport").jqGrid("getGridParam", "selarrrow");
            return idsel.join(",");
        },
        selectedBrnWork: function () { return $('#hiddenField').val(); }
    }