Question

I need to set a custom http header before 'Edit' (PUT) only. I tried the loadBeforeSend as mentioned here - How to set request header to the ajax object for jqGrid

loadBeforeSend: function(jqXHR) {
                alert('loadBeforeSend');
                jqXHR.setRequestHeader('If-Match', '*');
            },

But this function gets invoked before every request. I need this header to be set only on a 'PUT' request but not on any other. My 'GET' request actually fails with this header.

How do I check if it is a PUT or a GET inside the loadBeforeSend ? or is there another way to do this?

Thanks in advance!

Was it helpful?

Solution

You don't wrote which editing mode you use which is really important to get an exact answer on your question. In general jqGrid provide option ajaxRowOptions, ajaxEditOptions, ajaxCellOptions etc which allow you to customize jQuery.ajax calls which makes jqGrid internally. One can use beforeSend callback of jQuery.ajax to make customization which you require. By the way jqGrid uses the callback internally for loading of the grid and it calls loadBeforeSend callback if it exist. Other Ajax calls made by jqGrid don't use beforeSend callback and so you have no callback like loadBeforeSend.

So you should just specify beforeSend callback which do the same what you want to do inside of loadBeforeSend callback, but you need place beforeSend inside of ajaxRowOptions, ajaxEditOptions, ajaxCellOptions and so on depend on editing mode which you use. You can find example of such implementations in the answer, this one, this one and some another answers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top