From e3349693c533c17fb9b6a770a8360b64ec337c68 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 9 Jul 2011 21:24:14 -0400 Subject: make less confusing --- docs/narr/webob.rst | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'docs/narr/webob.rst') diff --git a/docs/narr/webob.rst b/docs/narr/webob.rst index 373ae5896..beb319084 100644 --- a/docs/narr/webob.rst +++ b/docs/narr/webob.rst @@ -256,8 +256,8 @@ does not have a body, or the body is not a properly JSON-encoded value, an exception will be raised when this attribute is accessed. This attribute is useful when you invoke a Pyramid view callable via -e.g. jQuery's ``$.post`` or ``$.ajax`` functions, which have the potential to -send a JSON-encoded body or parameters. +e.g. jQuery's ``$.ajax`` function, which has the potential to send a request +with a JSON-encoded body. Using ``request.json_body`` is equivalent to: @@ -275,18 +275,17 @@ is sent to a Pyramid application: jQuery.ajax({type:'POST', url: 'http://localhost:6543/', // the pyramid server data: JSON.stringify({'a':1}), - contentType: 'application/json; charset=utf-8', - dataType: 'json'}); + contentType: 'application/json; charset=utf-8'}); When such a request reaches a view in your application, the ``request.json_body`` attribute will be available in the view callable body. .. code-block:: javascript - @view_config(renderer='json') + @view_config(renderer='string') def aview(request): print request.json_body - return {'result':'OK'} + return 'OK' For the above view, printed to the console will be: -- cgit v1.2.3