AJAX


HTML pages use JavaScript and cascading style sheets to provide dynamic content.

Implementing AJAX technologies is possible to update part of a web page, without reloading the whole page.

Avior returns data encoded ISO-8859-1, thus it's important to preset the charset of all AJAX requests. Put the following code before to start any request.


$.ajaxSetup ({

  'beforeSend' : function(xhr) {

    xhr.overrideMimeType('text/html; charset=iso-8859-1'); 

  }

});


You can handle AJAX requests with a standard XMLHttpRequest or via JQuery.

To retrieve information from Avior you need to initiate a GET request.

Here below a simplified example to GET the log from the device.


Native JavaScript XMLHttpRequest


var xhr = new XMLHttpRequest();

xhr.open('GET', '/readlog');        // method & enpoint

xhr.onload = function() {

  // handle  xhr.status

  // process xhr.responseText

}

xhr.send();


JQuery


$.ajax({

  type: "GET",

  url: "/readlog",        // endpoint

  timeout: 2000,

  success: function(data) {

    // called when successful

    // process received data

  },

  error: function(data, status) {

    // called when there is an error

       // handle error

  }

});


To send commands to Avior you need to initiate a POST request.

Here below a simplified example to POST command to device.


JavaScript XMLHttpRequest


xhr = new XMLHttpRequest();

xhr.open('POST', '/cmd');        // method & enpoint

xhr.onload = function() {

  // handle  xhr.status

  // process xhr.responseText

};

xhr.send('AT');


JQuery


$.ajax({

  type: "POST",

  url: "/cmd",        // endpoint

  data: "AT",

  timeout: 2000,

  success: function(data) {

    // called when successful

    // process received data

  },

  error: function(data, status) {

    // called when there is an error

       // handle error

  }

});


Complete reference available here: