refactor server side of AJAX and JSON examples