passing json from seaside to javascript

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

passing json from seaside to javascript

sergio_101
i am currently working on an app that uses a javascript library to render the state of an object inside seaside. i am trying to figure out the best way to transfer the state of object to javascript.

the state of the machine changes via form inputs and ajax.

i already have the code to convert the state of my object to json, so i am thinking i can do this one of two ways..

via ajax, inject the json code into a variable in a function that is fired off by ajax. i just am not sure how to inject this json string into the page where it would look like the contents of a variable. any ideas?

or, i could make a component that just spits out the current state as a json string. this way, when the value of a form element changes, that value is sent over ajax to seaside, and seaside can answer back with the new state as a json string. i am just not sure how to implement this, either. any ideas?

let me know if there is a better approach to this, also.

thanks!
Reply | Threaded
Open this post in threaded view
|

Re: passing json from seaside to javascript

Esteban A. Maringolo
Sergio,

I don't fully understand what you need to do.

1. Do you need to pass a JSON object to a globally accessible
javascript function?
2. Is the JSON object dynamically generated as a response to an AJAX call?

Regards!






Esteban A. Maringolo


2015-01-16 12:11 GMT-03:00 sergio_101 <[hidden email]>:

> i am currently working on an app that uses a javascript library to render
> the state of an object inside seaside. i am trying to figure out the best
> way to transfer the state of object to javascript.
>
> the state of the machine changes via form inputs and ajax.
>
> i already have the code to convert the state of my object to json, so i am
> thinking i can do this one of two ways..
>
> via ajax, inject the json code into a variable in a function that is fired
> off by ajax. i just am not sure how to inject this json string into the page
> where it would look like the contents of a variable. any ideas?
>
> or, i could make a component that just spits out the current state as a json
> string. this way, when the value of a form element changes, that value is
> sent over ajax to seaside, and seaside can answer back with the new state as
> a json string. i am just not sure how to implement this, either. any ideas?
>
> let me know if there is a better approach to this, also.
>
> thanks!

Reply | Threaded
Open this post in threaded view
|

Re: passing json from seaside to javascript

sergio_101
hi, esteban..

the json object is a representation of the pharo object. i just need to get that json object  (in its updated form) available to a javascript function..

the pseudo code for javascript would be something like:

control changed
update json object (pharo/seaside does this)
rerender section of screen using json

so, to answer both of your questions, yes..

thanks!


On Fri Jan 16 2015 at 10:41:27 AM Esteban A. Maringolo <[hidden email]> wrote:
Sergio,

I don't fully understand what you need to do.

1. Do you need to pass a JSON object to a globally accessible
javascript function?
2. Is the JSON object dynamically generated as a response to an AJAX call?

Regards!






Esteban A. Maringolo


2015-01-16 12:11 GMT-03:00 sergio_101 <[hidden email]>:
> i am currently working on an app that uses a javascript library to render
> the state of an object inside seaside. i am trying to figure out the best
> way to transfer the state of object to javascript.
>
> the state of the machine changes via form inputs and ajax.
>
> i already have the code to convert the state of my object to json, so i am
> thinking i can do this one of two ways..
>
> via ajax, inject the json code into a variable in a function that is fired
> off by ajax. i just am not sure how to inject this json string into the page
> where it would look like the contents of a variable. any ideas?
>
> or, i could make a component that just spits out the current state as a json
> string. this way, when the value of a form element changes, that value is
> sent over ajax to seaside, and seaside can answer back with the new state as
> a json string. i am just not sure how to implement this, either. any ideas?
>
> let me know if there is a better approach to this, also.
>
> thanks!

Reply | Threaded
Open this post in threaded view
|

Re: passing json from seaside to javascript

Esteban A. Maringolo
I'm writing without testing it, but I think it might work:

Option A.
1. Create a named, global javascript function from Seaside that will
be called as the callback for the "control changed" event.
2. Within that global function perform an AJAX JSON call to seaside
and pass its response to the javascript function (global?) that will
re-render the section of the screen.

This way you'll only have one function to handle the callback and one
seaside callback to handle the JSON request.

I'm doing something similar to what you need to handle events from a
JQ plugin and it works fine without leakage one the client or the
server.

Regards,


Esteban A. Maringolo


2015-01-16 13:08 GMT-03:00 sergio_101 <[hidden email]>:

> hi, esteban..
>
> the json object is a representation of the pharo object. i just need to get
> that json object  (in its updated form) available to a javascript function..
>
> the pseudo code for javascript would be something like:
>
> control changed
> update json object (pharo/seaside does this)
> rerender section of screen using json
>
> so, to answer both of your questions, yes..
>
> thanks!
>
>
> On Fri Jan 16 2015 at 10:41:27 AM Esteban A. Maringolo
> <[hidden email]> wrote:
>>
>> Sergio,
>>
>> I don't fully understand what you need to do.
>>
>> 1. Do you need to pass a JSON object to a globally accessible
>> javascript function?
>> 2. Is the JSON object dynamically generated as a response to an AJAX call?
>>
>> Regards!
>>
>>
>>
>>
>>
>>
>> Esteban A. Maringolo
>>
>>
>> 2015-01-16 12:11 GMT-03:00 sergio_101 <[hidden email]>:
>> > i am currently working on an app that uses a javascript library to
>> > render
>> > the state of an object inside seaside. i am trying to figure out the
>> > best
>> > way to transfer the state of object to javascript.
>> >
>> > the state of the machine changes via form inputs and ajax.
>> >
>> > i already have the code to convert the state of my object to json, so i
>> > am
>> > thinking i can do this one of two ways..
>> >
>> > via ajax, inject the json code into a variable in a function that is
>> > fired
>> > off by ajax. i just am not sure how to inject this json string into the
>> > page
>> > where it would look like the contents of a variable. any ideas?
>> >
>> > or, i could make a component that just spits out the current state as a
>> > json
>> > string. this way, when the value of a form element changes, that value
>> > is
>> > sent over ajax to seaside, and seaside can answer back with the new
>> > state as
>> > a json string. i am just not sure how to implement this, either. any
>> > ideas?
>> >
>> > let me know if there is a better approach to this, also.
>> >
>> > thanks!
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: passing json from seaside to javascript

sergio_101
oh! i was going to write the javascript function in an included javascript file.. i didn't know you could define javascript functions on the seaside side..

On Fri Jan 16 2015 at 11:59:15 AM Esteban A. Maringolo <[hidden email]> wrote:
I'm writing without testing it, but I think it might work:

Option A.
1. Create a named, global javascript function from Seaside that will
be called as the callback for the "control changed" event.
2. Within that global function perform an AJAX JSON call to seaside
and pass its response to the javascript function (global?) that will
re-render the section of the screen.

This way you'll only have one function to handle the callback and one
seaside callback to handle the JSON request.

I'm doing something similar to what you need to handle events from a
JQ plugin and it works fine without leakage one the client or the
server.

Regards,


Esteban A. Maringolo


2015-01-16 13:08 GMT-03:00 sergio_101 <[hidden email]>:
> hi, esteban..
>
> the json object is a representation of the pharo object. i just need to get
> that json object  (in its updated form) available to a javascript function..
>
> the pseudo code for javascript would be something like:
>
> control changed
> update json object (pharo/seaside does this)
> rerender section of screen using json
>
> so, to answer both of your questions, yes..
>
> thanks!
>
>
> On Fri Jan 16 2015 at 10:41:27 AM Esteban A. Maringolo
> <[hidden email]> wrote:
>>
>> Sergio,
>>
>> I don't fully understand what you need to do.
>>
>> 1. Do you need to pass a JSON object to a globally accessible
>> javascript function?
>> 2. Is the JSON object dynamically generated as a response to an AJAX call?
>>
>> Regards!
>>
>>
>>
>>
>>
>>
>> Esteban A. Maringolo
>>
>>
>> 2015-01-16 12:11 GMT-03:00 sergio_101 <[hidden email]>:
>> > i am currently working on an app that uses a javascript library to
>> > render
>> > the state of an object inside seaside. i am trying to figure out the
>> > best
>> > way to transfer the state of object to javascript.
>> >
>> > the state of the machine changes via form inputs and ajax.
>> >
>> > i already have the code to convert the state of my object to json, so i
>> > am
>> > thinking i can do this one of two ways..
>> >
>> > via ajax, inject the json code into a variable in a function that is
>> > fired
>> > off by ajax. i just am not sure how to inject this json string into the
>> > page
>> > where it would look like the contents of a variable. any ideas?
>> >
>> > or, i could make a component that just spits out the current state as a
>> > json
>> > string. this way, when the value of a form element changes, that value
>> > is
>> > sent over ajax to seaside, and seaside can answer back with the new
>> > state as
>> > a json string. i am just not sure how to implement this, either. any
>> > ideas?
>> >
>> > let me know if there is a better approach to this, also.
>> >
>> > thanks!
>>
>