You response is received by the JS so no coversion is necessary> My
guess is
function Save() {
var data = $.toJSON( ....# I convert JSON object to simple text
here....));
$.ajax({
type: 'POST',
url: '{{=URL(r=request,f='action')}}',
contentType: "application/json;
charset=utf-8",
data: data,
dataType: 'json'
success: function(data){ alert(eval
('('+data+')')["Name"][0]["key1"]); }
});
});
}
On Mar 31, 11:42 am, Yannick <[email protected]> wrote:
> Thanks Massimo But inside my callback method i do receive another JSON
> message as response and I want to parse it for display... Do you know
> How i can do it then ?
>
> Thanks,
> Yannick P.
>
> On Mar 31, 12:22 pm, mdipierro <[email protected]> wrote:
>
> > You have a logical problem. the sj.loads must be in the action that
> > receives the ajax call "action" in your case. It cannot be embedded in
> > the JS code that makes the call.
>
> > On Mar 31, 9:24 am, Yannick <[email protected]> wrote:
>
> > > Hello mate
> > > I'm trying to parse the JSON object inside the callback method from my
> > > client side, I got a message saying "No JSON object could be
> > > decoded"... Do you please have any idea about what I'm doing wrong in
> > > my callback method...Below you can see the sample of the callback
> > > method, and format of JSON message sent from server... thanks
>
> > > # from the client side I receive a JSON msg in callback that i want
> > > to parse:
>
> > > function Save() {
> > > var data = $.toJSON( ....# I convert JSON object to simple text
> > > here....));
> > > $.ajax({
> > > type: 'POST',
> > > url: '{{=URL(r=request,f='action')}}',
> > > contentType: "application/json;
> > > charset=utf-8",
> > > data: data,
> > > dataType: 'json'
> > > success: function(data){ {{
> > > import
> > > gluon.contrib.simplejson as sj
> > > data = sj.loads
> > > (response.body.read())
> > > value = data
> > > ["Name"][0]["key1"]
> > > }}
> > > alert({{=value}}); }
> > > });
> > > });
>
> > > }
>
> > > Here is the format of the JSON that is sent as a response from my
> > > action client (I can see it from Firebug debuger)
>
> > > {
> > > "Name":
> > > [
> > > { "Key1": "value1",
> > > "key2": value2,
> > > "data": {"key": "value3"}
> > > },
> > > { "Key1": "value1",
> > > "key2": value2,
> > > "data": {"key": "value3"}
> > > },
> > > ]
>
> > > }
>
> > > Any ideas ?
>
> > > This is the follow-up of this
> > > thread:http://groups.google.com/group/web2py/browse_thread/thread/3a61efd564...
>
> > > 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 [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
-~----------~----~----~----~------~----~------~--~---