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: 15,240Questions: 1Answers: 2,599

    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: 63,691Questions: 1Answers: 10,500 Site admin

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

    Allan

This discussion has been closed.