How to set request header for ajax object for jqGrid

I need to set the authorization request header to httpXMLRequest. In the grid definition, I tried to set through ajaxGridOptions, as shown below:

ajaxGridOptions: { Authorization: 'Basic YWRtaW5AZGVmYXVsdC5jb206YWRTwa6=' } 

and use the beforeSend event as shown below:

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

None of this works for me. What is the correct syntax?

Thanks!!

+6
source share
2 answers

You can use, for example, loadBeforeSend the jqGrid event handler, defined as follows:

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

Another option for today is to set up a global header for all AJAX requests:

 $.ajaxSetup({ headers : { 'Authorization' : 'Basic YWRtaW5AZGVmYXVsdC5jb206YWRTwa6=' } }); 
0
source

Source: https://habr.com/ru/post/886166/


All Articles