Error in 401 (Unauthorized) option callback

Error in 401 (Unauthorized) option callback

ycusoyycusoy Posts: 27Questions: 5Answers: 0

I call data from the input text field from outside the DataTable. but then it can't be processed, for example:

js.

function admins() {
        var url = $('#ipadd').val();
        $('#admin').DataTable({
            "dom": 'rt i<"bottom"flp><"clear">',
            "paging": false,
            "scrollY": '500px',
            "scrollX": false,
            "processing": true,
            "serverSide": true,
            "ajax": {
                "url": "http://" + url + "/cgi-bin/get_status.cgi",
                "dataSrc": "summary",
            },
            "error": function() {
                console.log("error encountered ! ");
            },
            "columns": [{

                "data": "elapsed",
                "title": "Durasi"
            }]

        })
    }

html.

<center>
<input type="text" style="display:block" id="ipadd">
<button class="wlt" onclick="admins();">Check Data</button></center>
<table id="admin" class="display" width="100%">
<thead>
</thead>
<tbody>
</tbody>
<tfoot>
</tfoot>
</table>

console.
GET http://192.168.0.100/cgi-bin/get_status.cgi?draw=1&columns%5B0%5D%5Bdata%5D=elapsed&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=-1&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1561552422952 401 (Unauthorized)
jquery-3.3.1.js:9600

Answers

  • daduffydaduffy Posts: 31Questions: 5Answers: 1

    If you are getting a 401 server error, then nothing will come back until that problem is fixed.

    Are you able to navigate to http://192.168.0.100/cgi-bin/get_status.cgi in your browser or via cURL? What is returned?

  • ycusoyycusoy Posts: 27Questions: 5Answers: 0

    yes of course it can be normal in the browser, only when I access the address directly will I be asked to authenticate my username and password. after I fill it, json data will appear. is there a way to pass it? or like adding a login line to ajax?

  • daduffydaduffy Posts: 31Questions: 5Answers: 1

    @ycusoy

    That really depends on your authentication scripts, however you chose to do it, you can.

    You could add some form of authentication within the ajax call, but you need to be really careful how you do that, I making sure not to expose yourself to someone getting access to your script.

    Why don't you make sure that someone has a vaild logged in session before you give them access to your Datatable page instead?

    Or, if the data isn't sensitive, why not just display it on a different page?

    Dave

  • ycusoyycusoy Posts: 27Questions: 5Answers: 0

    Yes, right. the confidentiality of this script only applies locally. it's just that, I want to combine some data from outside for data analysis purposes. to display on another page will impact back and forth between pages and of course it's a slightly slow step. are there certain lines on ajax that allow direct access without authentication?

This discussion has been closed.