r9694 - helma-ng/trunk/modules/helma/webapp

[email protected] Thu, 30 Apr 2009 22:07:20 +0200 (CEST)
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20090430200720.64F543D0D6@mia>
Author: hannes
Date: 2009-04-30 22:07:20 +0200 (Thu, 30 Apr 2009)
New Revision: 9694

Modified:
   helma-ng/trunk/modules/helma/webapp/response.js
Log:
Add JSONResponse

Details at http://dev.helma.org/trac/helma/changeset/9694

Modified: helma-ng/trunk/modules/helma/webapp/response.js
===================================================================
--- helma-ng/trunk/modules/helma/webapp/response.js	2009-04-30 13:04:43 UTC (rev 9693)
+++ helma-ng/trunk/modules/helma/webapp/response.js	2009-04-30 20:07:20 UTC (rev 9694)
@@ -2,7 +2,7 @@
 include('helma/buffer');
 include('helma/webapp/util');
 
-export('Response', 'SkinnedResponse', 'RedirectResponse' /*, 'NotFoundResponse', 'ServerErrorResponse'*/);
+export('Response', 'SkinnedResponse', 'JSONResponse', 'RedirectResponse' /*, 'NotFoundResponse', 'ServerErrorResponse'*/);
 
 function Response() {
 
@@ -154,6 +154,13 @@
     return new Response(render(skin, context, scope));
 }
 
+function JSONResponse(object) {
+    var json = require('core/json2').JSON;
+    var res = new Response(json.stringify(object));
+    res.contentType = 'application/json';
+    return res;
+}
+
 function RedirectResponse(location) {
     return [303, {Location: location}, "See other: " + location];
 }