How to pass Authorization header with parameters in DataTable Ajax call

How to pass Authorization header with parameters in DataTable Ajax call

shweta24julyshweta24july Posts: 1Questions: 1Answers: 0

I need to pass Authorization header token with ajax call below is code I am trying

             sServerMethod: 'post',
            "ajax": {
                "url": 'http://localhost:111111/api/Support/GetAllTickets',
                "dataType": 'json',
                "type": 'Post',

                "beforeSend": function (xhr) {
                    xhr.setRequestHeader('Authorization',
                        "Bearer " + sessionStorage.getItem('accesstoken'));
                },
                "fnServerParams": function (aoData) {

                    aoData.push({ "name": "sdisp", "value": selectedval });
                    aoData.push({ "name": "ticketbystatus", "value": typeofticket });
                },
            },

this is reaching to web API but parameters is not passed.
Please help

Answers

  • colincolin Posts: 3,034Questions: 0Answers: 525

    Hi @shweta24july ,

    This thread here may help - it's discussing the same issue. Also, this may be useful,

    Cheers,

    Colin

  • MichałSucheckiMichałSuchecki Posts: 1Questions: 0Answers: 0

    There's 'headers' property:

    "ajax": {
        (...)
        "headers": {
            "Authorization": "Bearer: ......"
        },
    },
    
  • allanallan Posts: 48,452Questions: 1Answers: 7,015 Site admin

    There is no fnServerParams option in the ajax object. You want ajax.data.

    Allan

Sign In or Register to comment.