Kevin Haverlock
<script>
var timer = null;
// Function that retrieves a JSON object and puts the information
// into the div with an id of 'json-content'. Notice how we're defining
// 'handleAs' to be of type 'text'. We we handle the parsing of the JSON
// data so that we can trap the exception if it occurs.
function getJson () {
var d = dojo.xhrGet ({
url: '/webseal/login',
handleAs: 'text',
load: loadIntoNode,
error: errorCondition
});
};
function loadIntoNode(data, ioArgs){
try{
console.log("Read JSON Data ... do something",data);
// read the JSON data that was returned by the service
var jsonData = dojo.fromJson(data);
console.log(jsonData.attribute);
console.log(jsonData.number);
//do something with the JSON data that you read
//dojo.byId("json-content").innerHTML = data;
}catch(e)
{
// respond with an error reading JSON. As an example, if an HTML form login is returned, then dojo.fromJson
// will throw an Exception. Catch the exception and dispaly a login box. At this point, we are assuming the
// error condition is because Dojo can't parse the JSON stream. You can fine tune the error condition by
// looking at the e.message value
console.log("error reading json data ",e.message);
// Do something on the error condition, display a login widget, or look at the ioArgs to further narrow
// the problem down.
}
function errorCondition(error,ioArgs){
console.log("Status",ioArgs.xhr.status);
// retrieve an error message for the HTTP response code. As an example, if we get a 500
// (Server Error) then take an action.
switch(ioArgs.xhr.status) {
case 404: //page not found error
break;
case 500: // server side error
break;
case 407: // proxy authentication
break;
default: // default action
};
console.log("HTTP Error code:",ioArgs.xhr.status);
console.log("Error Condition:",error.responseText);
console.log("Error Message: ",error.message);
//dojo.byId("json-content").innerHTML = ioArgs.xhr.status;
};
</script>