Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

adding parameter in request header in AJAX Call

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

Former Member
replied

Dude, really??

https://www.google.com/search?rlz=1C1CHFX_enUS566US566&{google:acceptedSuggestion}oq=jquery+ajax+post+http+header&source…

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

      $.ajax({

                             type : "GET",

                             contentType : 'application/json',

                             dataType : 'json',

                             crossDomain : true,

                             url : url,

             headers: {

                                  'api-key' : 'XXXXX',

                             userId : 'XXX',

                             password : 'XXXX',

             },

....

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question