如何将请求标头设置为 jqGrid 的 ajax 对象

2022-01-19 00:00:00 ajax jqgrid

我需要将授权"请求标头设置为 httpXMLRequest.在网格定义上,我尝试通过 ajaxGridOptions 进行设置,如下所示:

I have the need to set the 'Authorization' request header to the httpXMLRequest. On the grid definition I have tried to set via ajaxGridOptions like the following:

 ajaxGridOptions: { Authorization: 'Basic YWRtaW5AZGVmYXVsdC5jb206YWRTwa6=' } 

并使用如下的 beforeSend 事件:

and use the beforeSend event like the following:

   beforeSend:  function(jqXHR, settings) {
    jqXHR.setRequestHeader("Authorization", 'Basic YWRtaW5AZGVmYXVsdC5jb206YWRTwa6=');
                    }

以上都不适合我.什么是正确的语法?

None of above works for me. What's the right syntax?

谢谢!!

推荐答案

你可以使用例如 loadBeforeSend jqGrid 的事件处理函数定义如下:

You can use for example loadBeforeSend event handler of the jqGrid defined as the following:

loadBeforeSend: function(jqXHR) {
    jqXHR.setRequestHeader("Authorization", 'Basic YWRtaW5AZGVmYXVsdC5jb206YWRTwa6=');
}

相关文章