Getting json after an ajax call

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting json after an ajax call

Dave
Hi folks,

I can't retrieve a json from the server. I have an ajax call, on success I want to get some json in return.

Here is a sample code:

html jQuery ajax
                        callback: [ ... ] ;
                        onSuccess:
                                (html jQuery getJson
                                        json: [ :js |  js object:[(Dictionary new at:'aSampleKey' put:'aSampleValue'; yourself) asJson] ];
                                        onSuccess: 'console.log(arguments[0])')
                                                               
Unfortunately the console prints Object {}

I guess there is something wrong with js object:[] but I've no idea of what

Dave
Reply | Threaded
Open this post in threaded view
|

Re: Getting json after an ajax call

Paul DeBruicker

try  

'console.log(JSON.stringify(arguments[0])'





Dave wrote
Hi folks,

I can't retrieve a json from the server. I have an ajax call, on success I want to get some json in return.

Here is a sample code:

html jQuery ajax
                        callback: [ ... ] ;
                        onSuccess:
                                (html jQuery getJson
                                        json: [ :js |  js object:[(Dictionary new at:'aSampleKey' put:'aSampleValue'; yourself) asJson] ];
                                        onSuccess: 'console.log(arguments[0])')
                                                               
Unfortunately the console prints Object {}

I guess there is something wrong with js object:[] but I've no idea of what

Dave
Reply | Threaded
Open this post in threaded view
|

Re: Getting json after an ajax call

Paul DeBruicker
errr... missing closing parenthesis in the previous email

'console.log(JSON.stringify(arguments[0]))'






Paul DeBruicker wrote
try  

'console.log(JSON.stringify(arguments[0])'





Dave wrote
Hi folks,

I can't retrieve a json from the server. I have an ajax call, on success I want to get some json in return.

Here is a sample code:

html jQuery ajax
                        callback: [ ... ] ;
                        onSuccess:
                                (html jQuery getJson
                                        json: [ :js |  js object:[(Dictionary new at:'aSampleKey' put:'aSampleValue'; yourself) asJson] ];
                                        onSuccess: 'console.log(arguments[0])')
                                                               
Unfortunately the console prints Object {}

I guess there is something wrong with js object:[] but I've no idea of what

Dave
Reply | Threaded
Open this post in threaded view
|

Re: Getting json after an ajax call

Dave
Hi Paul,
No change. The console shows {}

I was expecting {"aSampleKey":"aSampleValue"}
Dave

Paul DeBruicker wrote
errr... missing closing parenthesis in the previous email

'console.log(JSON.stringify(arguments[0]))'






Paul DeBruicker wrote
try  

'console.log(JSON.stringify(arguments[0])'





Dave wrote
Hi folks,

I can't retrieve a json from the server. I have an ajax call, on success I want to get some json in return.

Here is a sample code:

html jQuery ajax
                        callback: [ ... ] ;
                        onSuccess:
                                (html jQuery getJson
                                        json: [ :js |  js object:[(Dictionary new at:'aSampleKey' put:'aSampleValue'; yourself) asJson] ];
                                        onSuccess: 'console.log(arguments[0])')
                                                               
Unfortunately the console prints Object {}

I guess there is something wrong with js object:[] but I've no idea of what

Dave
Reply | Threaded
Open this post in threaded view
|

Re: Getting json after an ajax call

Johan Brichau-2
Dave,

You are mixing the use of the JSON canvas api and the conversion of Smalltalk object to JSON.
Take a look at an example in JQJsonFunctionalTest>>renderJsonCallbackOn: or in WAJsonRenderingTest

Either do:

js object: [ js key: ‘aSampleKey’ value: ‘aSampleValue’ ]

or:

js render: (Dictionary new at:’aSampleKey’ put: ‘aSampleValue’; yourself)

The first one uses the json canvas api to directly generate JSON on the document. The second one renders the JSON representation of Smalltalk objects on the document.

cheers
Johan

On 21 Jul 2016, at 07:41, Dave <[hidden email]> wrote:

Hi Paul,
No change. The console shows {}

I was expecting {"aSampleKey":"aSampleValue"} 
Dave


Paul DeBruicker wrote
errr... missing closing parenthesis in the previous email

'console.log(JSON.stringify(arguments[0]))'





Paul DeBruicker wrote
try  

'console.log(JSON.stringify(arguments[0])'




Dave wrote
Hi folks,

I can't retrieve a json from the server. I have an ajax call, on success
I want to get some json in return.

Here is a sample code:

html jQuery ajax
callback: [ ... ] ;
onSuccess:
(html jQuery getJson
json: [ :js |  js object:[(Dictionary new at:'aSampleKey'
put:'aSampleValue'; yourself) asJson] ];
onSuccess: 'console.log(arguments[0])')

Unfortunately the console prints Object {}

I guess there is something wrong with js object:[] but I've no idea of
what

Dave





--
View this message in context: http://forum.world.st/Getting-json-after-an-ajax-call-tp4907286p4907306.html
Sent from the Seaside General mailing list archive at Nabble.com.
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Getting json after an ajax call

Dave
Thanks Johan, now it's clear.

I had previously looked at JQJsonFunctionalTest>>renderJsonCallbackOn: but it didn't clarify a lot.

WAJsonRenderingTest is not in the 'Base' Seaside package, I had to download the full one

Gofer new
    url:'http://www.smalltalkhub.com/mc/Seaside/MetacelloConfigurations/main';
    package: 'ConfigurationOfSeaside3';
    load.
((Smalltalk at: #ConfigurationOfSeaside3) project version: #stable) load: 'CI'.

Thank you very much
Dave


Johan Brichau-2 wrote
Dave,

You are mixing the use of the JSON canvas api and the conversion of Smalltalk object to JSON.
Take a look at an example in JQJsonFunctionalTest>>renderJsonCallbackOn: or in WAJsonRenderingTest

Either do:

        js object: [ js key: ‘aSampleKey’ value: ‘aSampleValue’ ]

or:

        js render: (Dictionary new at:’aSampleKey’ put: ‘aSampleValue’; yourself)

The first one uses the json canvas api to directly generate JSON on the document. The second one renders the JSON representation of Smalltalk objects on the document.

cheers
Johan

> On 21 Jul 2016, at 07:41, Dave <[hidden email]> wrote:
>
> Hi Paul,
> No change. The console shows {}
>
> I was expecting {"aSampleKey":"aSampleValue"}
> Dave
>
>
> Paul DeBruicker wrote
>> errr... missing closing parenthesis in the previous email
>>
>> 'console.log(JSON.stringify(arguments[0]))'
>>
>>
>>
>>
>>
>> Paul DeBruicker wrote
>>> try  
>>>
>>> 'console.log(JSON.stringify(arguments[0])'
>>>
>>>
>>>
>>>
>>> Dave wrote
>>>> Hi folks,
>>>>
>>>> I can't retrieve a json from the server. I have an ajax call, on success
>>>> I want to get some json in return.
>>>>
>>>> Here is a sample code:
>>>>
>>>> html jQuery ajax
>>>> callback: [ ... ] ;
>>>> onSuccess:
>>>> (html jQuery getJson
>>>> json: [ :js |  js object:[(Dictionary new at:'aSampleKey'
>>>> put:'aSampleValue'; yourself) asJson] ];
>>>> onSuccess: 'console.log(arguments[0])')
>>>>
>>>> Unfortunately the console prints Object {}
>>>>
>>>> I guess there is something wrong with js object:[] but I've no idea of
>>>> what
>>>>
>>>> Dave
>
>
>
>
>
> --
> View this message in context: http://forum.world.st/Getting-json-after-an-ajax-call-tp4907286p4907306.html <http://forum.world.st/Getting-json-after-an-ajax-call-tp4907286p4907306.html>
> Sent from the Seaside General mailing list archive at Nabble.com <http://nabble.com/>.
> _______________________________________________
> seaside mailing list
> [hidden email] <mailto:[hidden email]>
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside <http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside>

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside