The following code excerpt sends an AJAX request to list all ZyPer encoders and decoders:
function zt(){
xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-
urlencoded");
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
procResp(xmlhttp.responseText);
}
}
xmlhttp.send(encodeURIComponent("commands:show device-status
all"));
}
In this example, the encodeURIComponent function has two parts: The request type,
which is commands and the command show device-status all. Refer to the
show device status
only request type that is supported and only a single command can be suppplied for each
request.
Here, we handle the AJAX response:
function procRespTest(jsonData){
var jsData = JSON.parse(jsonData);
# jsData.status may have the values:
# "Success"
# "Request failed authentication"
# "Server not running"
# "no commands provided"
#
if (jsData.status == "Success"){
var element = document.getElementById("responseError");
element.innerHTML = jsData.responses[0].error;
element = document.getElementById("responseWarning");
element.innerHTML = jsData.responses[0].warning;
element = document.getElementById("numObjectsInResponse");
element.innerHTML = jsData.responses[0].text.length;
}
else{
// Failed authentication
}
}
The JSON data is decoded using the JSON.parse() method. In this example, information
about the response data is displayed on the web page (HTML code not shown).
Command Request / Response
command for more information. Currently, commands is the
59
Advanced Operation
Need help?
Do you have a question about the ZyPer and is the answer not in the manual?
Questions and answers