Using Ajax/Json; Login Authentication - ZeeVee ZyPer User Manual

Management platform
Hide thumbs Also See for ZyPer:
Table of Contents

Advertisement

The AJAX/JSON programming interface allows developers to control the Management
Platform within browser-based applications. All calls to the server are asynchronous post/
receive operations using Javascript and do not require any specific HTML or CSS code.
We will present two examples in this section: Login authentication and command request/
response.
There are two methods to authenticate with the server. The first and recommended method
is to pass the username and password to rcLogin.php. The second method is to pass
the username and password in every AJAX request.
Once the server accepts the username and password, it will generate a secure cookie
called "userToken". This cookie will expire one hour after the last AJAX command is
received by the server. After the cookie expires, all other AJAX requests will result in a
failed authentication until rcLogin.php is called again. The following code excerpt is from
the zyperLogin() function within zyper.html:
...
...
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
procLoginResp(xmlhttp.responseText);
}
}
postdata = "";
postdata += encodeURIComponent("serverSocketName") + '=' +
encodeURIComponent(socketName) + '&' +
encodeURIComponent("username") + '=' +
encodeURIComponent(username) + '&' +
encodeURIComponent("password") + '=' +
encodeURIComponent(password) + '&';
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-
urlencoded");
xmlhttp.send(postdata);
}
The response is a string value. The variable resp can be "Success", "Failed", or "Server
not running".
function procLoginResp(jsonData) {
var resp = JSON.parse(jsonData);
...
...

Using AJAX/JSON

Login Authentication

58
Advanced Operation

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ZyPer and is the answer not in the manual?

Questions and answers

Table of Contents