BeforeSend with jQuery DataTables

BeforeSend with jQuery DataTables

blgsyrmhndsblgsyrmhnds Posts: 1Questions: 1Answers: 0
edited September 2018 in Free community support

How can I use BeforeSend ajax property with jquery datatables?because my server side api want autharization..I used headers instead of BeforeSend but it gave 405 error

that give 405 error

$(document).ready(function() {
  var username = localStorage.getItem("Username");
  var password = localStorage.getItem("Password");
  var url = "https://lim.com.tr/app/public/api/v1/policelerim";
  var table = $('#example').DataTable({
    "processing": false,
    "serverSide": false,
    "ajax": {
      url: url,
      type: "POST",
      BeforeSend: {
        'Authorization': "Basic " + btoa(username + ":" + password)
      },
    }
  });
});

I tried this but it still error

  $(document).ready(function() {
    var username="info@lim.com.tr";//localStorage.getItem("Username");
        var password="102030asd";//localStorage.getItem("Password");
        var url="https://lim.com.tr/app/public/api/v1/policelerim";


 $('#example')
    .on('preXhr.dt', function ( e, settings, data ) {
        data.Authorization = "Basic " + btoa(username + ':' + password);
    } ).dataTable( {
            "processing": true,
            "serverSide": true,
            "ajax":{
                "url": url,
                "type": "POST"

            }

} );

} );

I upload here if you want debug with browser

http://hybridsoftware.net/ha/policelerim.html

Answers

This discussion has been closed.