cancel
Showing results for 
Search instead for 
Did you mean: 

adding parameter in request header in AJAX Call

vivek_gaurav
Participant
0 Kudos

Hi All,

         I am trying to call AS400 DB Services in SAP UI5 using AJAX Call.

         In Service we have to pass 3 parameter in request header

     1. api-key

     2. UserId

     3. password

     I am calling URL using below code:

var url = "https://iservicesdev.mscdirect.com/process/svrbrokr?BRK_SERVICE_ID=Lookup&format=Json&Type=XXXX";

        jQuery.sap.require("sap.ui.model.odata.datajs");

       

        

        $.ajax({

                             type : "GET",

                             contentType : 'application/json',

                             dataType : 'json',

                             crossDomain : true,

                             url : url,

                             'api-key' : 'XXXXX',

                             userId : 'XXX',

                             password : 'XXXX',

                             success : function(response, status, request)

                             {

                            debugger

                                  console.log(response);

                                  console.log(response.LookupResponse.Rows.Row.length);

                                  var oModel = new sap.ui.model.json.JSONModel(response.LookupResponse.Rows);

                                  that.getView().setModel(oModel);

                                 

                             },

                             error : function(jqXHR, textStatus,errorThrown)

                             {

                                    alert(" No success");

                             }

        });

       

  },

But it is not able to pass those 3 parameter in request header.

I checked it in Chrome inspect element -> Network

It is not showing those 3 parameter.

But if i add these 3 parameter using Modify header Chrome plugin then those parameter get added in request header and works fine. which is not correct in production environment.

Kindly check my AJAX call.If you have any other way to do AJAX call ,please provide.

Thanks

Vivek

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

Dude, really??

https://www.google.com/search?rlz=1C1CHFX_enUS566US566&{google:acceptedSuggestion}oq=jquery+ajax+pos...

http://stackoverflow.com/questions/7686827/how-can-i-add-a-custom-http-header-to-ajax-request-with-j...

      $.ajax({

                             type : "GET",

                             contentType : 'application/json',

                             dataType : 'json',

                             crossDomain : true,

                             url : url,

             headers: {

                                  'api-key' : 'XXXXX',

                             userId : 'XXX',

                             password : 'XXXX',

             },

....

vivek_gaurav
Participant
0 Kudos

Thanks alot..

It got resolved

Answers (1)

Answers (1)

jonas-99
Explorer
0 Kudos

I got a strange Problem with my ajax POST

this is my Code for the Post.

in the Console from Chrome my Custom Header "Abc" is successfully added to the Request Headers.

But in the Backend i only recieve these standard Headers and my Custom Header is not there. When i change the Value of a standart Header, for example content-type this value is recieved correct. But when i add a Custom Header not.

deepak_h3
Participant
0 Kudos

Getting same problem - did you get resolution to this ?