Wednesday, June 14, 2006

JSON for Dummies part 2

Below are clipping from My Portal Project, JSON for Dummies part 2:

Change the JSON response so that we have a method called “actionToTake”, and call it directly:

{"ajaxReturn":
{"actionToTake" :
function(){
alert('The description and category fields are required.');
}
}
}


In the above sample we created the “actionToTake” object as a function, with no parameters. Now we can use the following code to process our action:

function processJsonResponse(originalRequest){
var domText = originalRequest.responseText;
var jsonResult = eval("(" + domText + ")");
jsonResult.ajaxReturn.actionToTake();
}


This is another example of JSON strength.

1 comment:

Anonymous said...
This comment has been removed by a blog administrator.