On Mar 28, 3:38 pm, Yannick <ytchatch...@gmail.com> wrote:
> Hello mate,
> I have a question I don't know how to retrieve a JSON message sent to
> the Action from the client:
>
> # Here is a sample of my View:
> ....
> <script src="{{=URL(r=request,c='static/js',f='jquery-1.3.2.js')}}"
> type="text/javascript"></script>
> .....
> .....
> function Save() {
>
>                         var data = $.toJSON( ....# I convert JSON object to 
> simple text
> here....));

First, var data has to follow these rules (from jQuery API docs):

Data to be sent to the server. It is converted to a query string, if
not already a string. It's appended to the url for GET-requests. See
processData option to prevent this automatic processing. Object must
be Key/Value pairs. If value is an Array, jQuery serializes multiple
values with same key i.e. {foo:["bar1", "bar2"]} becomes
'&foo=bar1&foo=bar2'.

>
>                         $.ajax({
>
>                                 type: 'POST',
>
>                                 url: '{{=URL(r=request,f='action')}}',
>
>                                 contentType: "application/json; 
> charset=utf-8",
>
>                                 data: data,
>
>                                 dataType: 'json'
>
>                 });
>
>                 }
>
> I wanted to know How to load the value sent from the client in the
> action on the server so i can process them.

In your action you would check the request.vars for the keys of the
key/value pairs included in data, e.g. if

    data= "id="+somevalue

then in action you obtain the value of key id as follows:

    id=request.vars.id

BTW, to be useful you would probably need the callback inside your
$.ajax :

    success: function(datain) { ... }


>
> I'm using FireBug i can see the request sent and the Post message in
> JSON format. I think and believe everything is fine on the client side
> I just don't know how to retrieve them on the server side... Since
> here I don't use any argument or anything like that.
>
> Please any help would be appreciated.
>
> Thanks,
> Yannick P.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to