Hi DenesL, Massimo, thanks for your help on this, it works... Coming
from JAVA/J2EE world few months ago I didn't know I'll enjoy Python
and Web2py that much... I hope and wish this interesting experience
will benefit to someone else very soon...
Just for the info in case someone else follow this thread:
In the callback method above, instead of having
success: function(data){ alert(eval ('('+data+')')["Name"]
[0]["key1"]); }
Use the following:
success: function(data){ alert(eval(data)["Name"][0]
["key1"]); }
Otherwise you will get a JavaScript error message saying: "missing ]
after element list" this is due to the quote ' inside the eval()... So
basically just remove them.
Thanks again.
Yannick P.
On Mar 31, 2:55 pm, DenesL <[email protected]> wrote:
> Let me go over this quickly:
>
> > var data = $.toJSON( ....# I convert JSON object to simple text
>
> here you create a JSON encoded 'data' object, which is in line with
> the following jQuery (Javascript) code:
>
> > $.ajax({
> > type: 'POST',
> > url: '{{=URL(r=request,f='action')}}',
> > contentType: "application/json;
> > charset=utf-8",
> > data: data,
>
> this means that you will be sending a JSON encoded 'data' in the
> request body of a POST to your action (hence the need for sj.loads
> (response.body.read()) on the server side). Side note: this is in
> contrast to a GET method which encodes 'data' in a query string.
>
> > dataType: 'json'
>
> this means you expect the response from the server to be in JSON
>
> > success: function(data){ {{
>
> this function is called when the ajax request finishes successfully
> and 'data' will contain the response from the server (should be in
> JSON as specified above, so somewhere in your action you have to make
> sure it is).
> Your success function has to manipulate 'data' using Javascript (not
> Python) to obtain the info you need.
>
> > import
> > gluon.contrib.simplejson as sj
> > data = sj.loads
> > (response.body.read())
> > value = data
> > ["Name"][0]["key1"]
> > }}
> > alert({{=value}}); }
> > });
> > });
>
> > }
>
> Hope this helps.
> Denes.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---