NodeJS server and ajax.reload()

NodeJS server and ajax.reload()

Taylor514ceTaylor514ce Posts: 74Questions: 8Answers: 0

I have a a call to the ajax.reload() function on a setInterval timer. The call works, but fails to pass along the NodeJS authentication headers, including username. It's as if each call using reload() creates a new session, so NodeJS returns the login page rather than the expected JSON data. If I turn off NodeJS authentication, everything works fine.

Is there a way to configure/force ajax.reload() to pass along the current Session data, including any/all authentication headers?

Answers

  • allanallan Posts: 63,234Questions: 1Answers: 10,417 Site admin

    If you could post a link to a test case showing the issue, I'd be happy to take a look.

    When you call ajax.reload() it will trigger an Ajax call based on the configuration of the ajax option.

    Allan

  • Taylor514ceTaylor514ce Posts: 74Questions: 8Answers: 0

    I'm not sure how I'd create a test case or where to put it... I'm constructing this on a VM. Code for the table pasted below.

    On first request, NodeJS returns the login page, and upon success redirects to my home page.

    When the page first loads, the table populates correctly. Every subsequent time (when reload() is invoked by setInterval), I get a JSON error for the table, because NodeJS doesn't see any authentication information in the requests, and redirects back to the login page. The login page isn't valid JSON, of course, thus the error.

      obj_tblCourses = $('#tblCourses').DataTable( {
        initComplete: function(settings, json) {
                // Apply the search
                this.api().columns().every( function () {
                    var that = this;
     
                    $( 'input', this.footer() ).on( 'keyup change clear', function () {
                        if ( that.search() !== this.value ) {
                            that
                                .search( this.value )
                                .draw();
                        }
                    } );
                } );
            },
        sDom: '<"H">t<"F">',
        processing: true,
        serverSide: false,
        scrollY: $(document).height() - 320,
        scrollCollapse: true,
        paging: false,
        info: false,
        order: [[ 0, "asc" ]],
        columnDefs: [
        {
          targets: [1],
          createdCell: function (td, cellData, rowData, row, col) {
            $('a', td).eq(0).attr('onclick', 'getCourse(' +rowData[0] + '); target="_blank"; return false;' );
          }
        } ],
        ajax: 'fetchCourses'
      } );
      
      setInterval( function () {
        obj_tblCourses.ajax.reload( null, false );
      }, 10000 );
    
  • allanallan Posts: 63,234Questions: 1Answers: 10,417 Site admin

    Without a test case, all I can really say is that the configuration there will make a simple GET Ajax call to fetchCourses. No additional information is being sent, but I don't know if your authentication is session / cookie based, or something else.

    Allan

Sign In or Register to comment.