0

It seems that jqGrid event loadError is not triggered when GET returns error:

414 Request-URI Too Long

It can be reproduced by appending post data with data greater than 2048 bytes. Maybe someone knows how to use POST instead of GET request in jqGrid?

$grid.jqGrid({
    url:'/greenarrow_campaign_statistics/get_all_for_grid',
    datatype: "json",
    mtype: "POST",
    colNames:['Campaign Name', 'Last Date', '# of mailings', 'Recipients', 'Hard bounces', '%', 'Opens', '%', 'Clicks', '%', 'Upgrades', '%', 'FBL Compl.', '%'],
    colModel :[
        {name:'campaign_name', index:'campaign_name', width:220, sorttype:'text',align:'left',fixed:true},
        {name:'finishtime_str', index:'finishtime_sec', width:140, sorttype:'number',align:'center',fixed:true},
        {name:'count', index:'mailings_cnt', width:70, sorttype:'number',align:'right',fixed:true,hidden:true},
        {name:'recips_total', index:'recips_total', width:75, sorttype:'number',align:'right',fixed:true},
        {name:'num_bounces_hard', index:'num_bounces_hard', width:60, sorttype:'number',align:'right',fixed:true},
        {name:'num_bounces_hard_perc', index:'num_bounces_hard_perc', width:40, sorttype:'number',align:'right',fixed:true, formatter: percFormatter},
        {name:'num_opens', index:'num_opens', width:75, sorttype:'number',align:'right',fixed:true},
        {name:'num_opens_perc', index:'num_opens_perc', width:40, sorttype:'number',align:'right',fixed:true, formatter: percFormatter},
        {name:'num_clicks', index:'num_clicks', width:70, sorttype:'number',align:'right',fixed:true},
        {name:'num_clicks_perc', index:'num_clicks_perc', width:40, sorttype:'number',align:'right',fixed:true, formatter: percFormatter},
        {name:'num_upgrade', index:'num_upgrade', width:60, sorttype:'number',align:'right',fixed:true},
        {name:'num_upgrade_perc', index:'num_upgrade_perc', width:40, sorttype:'number',align:'right',fixed:true, formatter: percFormatter},
        {name:'num_fbl', index:'num_fbl', width:60, sorttype:'number',align:'right',fixed:true},
        {name:'num_fbl_perc', index:'num_fbl_perc', width:40, sorttype:'number',align:'right',fixed:true, formatter: percFormatter}
    ],
    rowList:[20, 30, 50, 100, 500],
    pager: '#pager',
    rowNum:20,
    shrinkToFit: true,
    sortname: 'finishtime_sec',
    viewrecords: true,
    sortorder: "desc",
    toolbar: [true, 'top'],
    multiselect: true,
    multiboxonly: true,
    footerrow: true,
    userDataOnFooter: true,
    height: "auto",
    caption:"",
    beforeRequest: function()
    {
        $grid.jqGrid(
            'appendPostData',
            {
                period: $period.val(),
                from: $('#start_date').val(),
                to: $('#end_date').val(),
                campaigns: $('input[name="campaign_names"]').val(),
                search_text: $('#search_text').val()
            });
    },
    ondblClickRow: function(id)
    {
        $('#btn_edit').trigger('click');
    },
    loadComplete: function(data) {
        $("tr.jqgrow:odd").css("background", "#DDDDDC");
    },
    loadError: function(xhr, status, error) {
        jQuery("#rsperror").html("Type: " + status + "; Response: " + xhr.status + " " + xhr.statusText);
    }
})
Oleg
  • 220,925
  • 34
  • 403
  • 798
savgoran
  • 55
  • 6

1 Answers1

0

If you examine the source code of jqGrid (see the lines) you fill see that jqGrid just uses jQuery.ajax. So it's probably a problem in jQuery version which you use.

In any way the origin of your problem is probably the usage of HTTP GET instead of usage HTTP POST. All parameters of GET request will be appended to the URL (as ?p1=v1&p2=v2&p3=v3...). There are exists restrictions in the URL length which are different in different browsers and different web servers (see here). For example Internet Explorer has a maximum length of URL of 2,083 characters (see here). Other web browsers have another limit of URL (see here for example).

From the design point of view it's strictly recommended to use POST instead of GET if the total size of URL could be larder of 2K (2048 characters). In the case you will have no problem with HTTP 414 error.

So you should modify your server code to reply of POST request and include mtype: "POST" option of jqGrid (or replace mtype: "GET" to mtype: "POST").

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanx Oleg, as you cen see my previous comment I already tried to set POST using mtype property, but jqGrid continue to use GET. I see it in FireBug. – savgoran Aug 14 '14 at 09:45
  • @savgoran: You are welcome! It means only that you either placed `mtype: "POST"` on the wrong place or you defined the value of `mtype` property **twice**: once with `"POST"` value and once more time with `"GET"` value. In any way you need analyse the source code (which you don't included in the text of your question). By the way you should place all information relation to the question *in the text* of the question and not in the comment. You can use "edit" button below of the question to modify the text of the question in any time. – Oleg Aug 14 '14 at 09:50
  • I have added source code, as you cen see mtype is added only once. – savgoran Aug 14 '14 at 09:56
  • @savgoran: I recommend you to use `jquery.jqGrid.src.js` (instead of `jquery.jqGrid.min.js`) of the last version of jqGrid and debug the code (you can use Developer Tools of IE for example, which you can start by pressing of F12). You can set breakpoint about [here](https://github.com/tonytomov/jqGrid/blob/v4.6.0/js/grid.base.js#L2002). Moreover I don't recommend to use obsolete `appendPostData` from `plugins/grid.postext.js` instead of that you can use `postData` with functions (see [the answer](http://stackoverflow.com/a/2928819/315935)). – Oleg Aug 14 '14 at 10:25
  • @savgoran: I would recommend you additionally to remove all `index` properties from `colModel`, remove default properties like `sorttype:'text',align:'left'`, define common properties (like `fixed:true`) using `cmTemplate: {fixed: true}` option and use column templates (see [the answer](http://stackoverflow.com/a/6047856/315935)). For example you have a lot of code duplicates with `width:40, sorttype:'number',align:'right', formatter: percFormatter`. You can define variable `var myNum = {width:40, sorttype:'number',align:'right',fixed:true, formatter: percFormatter}` and use `template: myNum` – Oleg Aug 14 '14 at 10:30
  • Do you want to say that you have not problem to change request type to POST? – savgoran Aug 14 '14 at 12:28
  • @savgoran: I use personally GET, POST and other and all works like I need. [The line](https://github.com/tonytomov/jqGrid/blob/v4.6.0/js/grid.base.js#L2010) of code just uses `mtype` in `$.ajax`, but it could be overwritten in some ways (directly, by usage `ajaxGridOptions` option, by setting it via `$.jgrid.ajaxOptions` and so on). I suppose that the problem is in *another part of your code which you don't posted here*. The most easy in my opinion is to start Developer Tools with F12, to set breakpoint near to [the line](https://github.com/tonytomov/jqGrid/blob/v4.6.0/js/grid.base.js#L2002). – Oleg Aug 14 '14 at 12:36
  • @savgoran: you can use additionally jQuery in non-minimized form and set breakpoint inside of `jQuery.ajax` to see the input parameters of `jQuery.ajax`. In the way you will find the reason of the problem very quickly. – Oleg Aug 14 '14 at 12:37
  • Last question, do you think that loadError should be raised if HTTP 414 error happen? – savgoran Aug 14 '14 at 12:42
  • @savgoran: In my opinion every HTTP status code which is 400 and higher (see [HTTP error](http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error)) should call `error` callback of jQuery.ajax and in the case jqGrid will call `loadError` – Oleg Aug 14 '14 at 13:00
  • @savgoran: You accepted the answer. Do you found the reason of why `mtype: "POST"` didn't work? What was the reason? – Oleg Aug 14 '14 at 13:01
  • No I didn't, but I have got many other usefull information. I thought that I must revard you somehow. In this case this is only way :) – savgoran Aug 14 '14 at 13:19
  • @savgoran: Please inform me (and other readers) when you'll find the reason. Do you tried to debug the Code using Developer Tools of IE? It's really easy. See [here](http://msdn.microsoft.com/en-us/library/ie/gg699336(v=vs.85).aspx) for example. You can see some videos like [here](https://www.youtube.com/watch?v=nH7HSLWaJ4o) or many other videos on youtube, or on channel9 like [here](http://channel9.msdn.com/Events/Build/2013/4-073), [here](http://channel9.msdn.com/Events/Build/2014/3-580) etc. – Oleg Aug 14 '14 at 13:39
  • You were in right. I have changed script in wrong layout. mtype: 'POST' works. Sorry for waisting your time. – savgoran Aug 14 '14 at 14:35
  • @savgoran: No problem. I like puzzles, but the best puzzle is the solved puzzle. I'm glad that I could help you. – Oleg Aug 14 '14 at 14:46