Noob jQuery AJAX question

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

Noob jQuery AJAX question

tfleig
Hi.

I want to, using AJAX, when the user selects a value from a list, pass that value to the server for processing and in response change the value of an item on the screen based on some server-side processing.

I expected to be able to do this in a single transaction with the server, but I have been unable to find a way to do so.

anAjax>>#serializeThis allows me to pass the selected value to the server, and anAjax>>#script: allows me to change the screen component value. I can't figure out how to combine this into a single server request. I don't seem to have access to an Ajax canvas object in the callback when I use serializeThis.

I hope I'm missing something simple.

Here is the toy test case I have been using:

enderContentOn: html

| val |

html div id: 'txt'; with: ''.
html break.
html select
list: { 1. 2. 3. };
selected: 2;
"Pass the selection back to the server and save it."
onChange: (html jQuery ajax serializeThis);
callback: [ :v |  val := v ];
"Set the div text to one less than the saved value"
onChange: (html jQuery ajax script: [ :s | s << (s jQuery: '#txt') text: (val - 1) ])

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

Re: Noob jQuery AJAX question

Nick
Hi

I want to, using AJAX, when the user selects a value from a list, pass that value to the server for processing and in response change the value of an item on the screen based on some server-side processing.

I expected to be able to do this in a single transaction with the server, but I have been unable to find a way to do so.

anAjax>>#serializeThis allows me to pass the selected value to the server, and anAjax>>#script: allows me to change the screen component value. I can't figure out how to combine this into a single server request. I don't seem to have access to an Ajax canvas object in the callback when I use serializeThis.

you could try something like this:

| val | html div id: 'txt'; with: ''. html break. html select list: { 1. 2. 3. }; selected: 2; "Pass the selection back to the server and save it." onChange: ((html jQuery ajax script: [ :s | s << (s jQuery: '#txt') text: (val - 1) ]) serializeThis); callback: [ :v | val := v ]


Nick

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

Re: Noob jQuery AJAX question

Nick
BTW I tend to use symbols for html ids - that way declaring and calling you use the same symbol and don't have to remember to add the # to the string when querying. Your method would then become:

| val | html div id: #txt; with: ''. html break. html select list: { 1. 2. 3. }; selected: 2; "Pass the selection back to the server and save it." onChange: ((html jQuery ajax script: [ :s | s << (s jQuery: #txt) text: (val - 1) ]) serializeThis); callback: [ :v | val := v ]


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

Re: Noob jQuery AJAX question

tfleig
In reply to this post by Nick
Wow. So simple when you know what you're doing.

It didn't occur to me that I could keep sending messages to the same JQAjax object.

Thanks.
TF

On Sun, Nov 14, 2010 at 10:03 AM, Nick Ager <[hidden email]> wrote:
Hi

I want to, using AJAX, when the user selects a value from a list, pass that value to the server for processing and in response change the value of an item on the screen based on some server-side processing.

I expected to be able to do this in a single transaction with the server, but I have been unable to find a way to do so.

anAjax>>#serializeThis allows me to pass the selected value to the server, and anAjax>>#script: allows me to change the screen component value. I can't figure out how to combine this into a single server request. I don't seem to have access to an Ajax canvas object in the callback when I use serializeThis.

you could try something like this:

| val | html div id: 'txt'; with: ''. html break. html select list: { 1. 2. 3. }; selected: 2; "Pass the selection back to the server and save it." onChange: ((html jQuery ajax script: [ :s | s << (s jQuery: '#txt') text: (val - 1) ]) serializeThis); callback: [ :v | val := v ]


Nick

_______________________________________________
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: Noob jQuery AJAX question

tfleig
I'm new enough to this that it seems like magic to me...

In the following onChange event, Seaside somehow arranges that the callback block is executed with the serialized parameter before the AJAX script object is executed, which is of course exactly what I want.

Is there a set of rules that are used to determine in what order these things occur? Is this documented somewhere?

renderContentOn: html
| val |

html div id: 'txt'; with: ''.
html break.
html select
list: { 1. 2. 3. };
selected: 2;
"Pass the selection back to the server and save it."
onChange: (
(html jQuery ajax)
script: [ :s | s << (s jQuery: '#txt') text: (val - 1)];
serializeThis);
callback: [ :v | val := v]


Rendering HTML with something like

    html div id: (html nextId); class: 'myclass'; with: 'mycontent'.

seems fairly straightforward, but the JQuery Ajax stuff doesn't seem nearly as clear.

Is there a description somewhere as to how this magic is accomplished? I'm somewhat overwhelmed perusing the code at the moment.

Thanks again.
TF




On Sun, Nov 14, 2010 at 10:18 AM, Tony Fleig <[hidden email]> wrote:
Wow. So simple when you know what you're doing.

It didn't occur to me that I could keep sending messages to the same JQAjax object.

Thanks.
TF

On Sun, Nov 14, 2010 at 10:03 AM, Nick Ager <[hidden email]> wrote:
Hi

I want to, using AJAX, when the user selects a value from a list, pass that value to the server for processing and in response change the value of an item on the screen based on some server-side processing.

I expected to be able to do this in a single transaction with the server, but I have been unable to find a way to do so.

anAjax>>#serializeThis allows me to pass the selected value to the server, and anAjax>>#script: allows me to change the screen component value. I can't figure out how to combine this into a single server request. I don't seem to have access to an Ajax canvas object in the callback when I use serializeThis.

you could try something like this:

| val | html div id: 'txt'; with: ''. html break. html select list: { 1. 2. 3. }; selected: 2; "Pass the selection back to the server and save it." onChange: ((html jQuery ajax script: [ :s | s << (s jQuery: '#txt') text: (val - 1) ]) serializeThis); callback: [ :v | val := v ]


Nick

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


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

Re: Noob jQuery AJAX question

tfleig
In reply to this post by Nick
Nice!

TF

On Sun, Nov 14, 2010 at 10:11 AM, Nick Ager <[hidden email]> wrote:
BTW I tend to use symbols for html ids - that way declaring and calling you use the same symbol and don't have to remember to add the # to the string when querying. Your method would then become:

| val | html div id: #txt; with: ''. html break. html select list: { 1. 2. 3. }; selected: 2; "Pass the selection back to the server and save it." onChange: ((html jQuery ajax script: [ :s | s << (s jQuery: #txt) text: (val - 1) ]) serializeThis); callback: [ :v | val := v ]


_______________________________________________
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: Noob jQuery AJAX question

Nick
In reply to this post by tfleig
Tony,
 
I'm new enough to this that it seems like magic to me...

In the following onChange event, Seaside somehow arranges that the callback block is executed with the serialized parameter before the AJAX script object is executed, which is of course exactly what I want.

Is there a set of rules that are used to determine in what order these things occur? Is this documented somewhere?

There's some documentation here: http://book.seaside.st/book/web-20/jquery

When I was experimenting with Seaside and JQuery I kept firebug open, examined the javascript that was generated and referred to the javascript JQuery documentation: http://docs.jquery.com/Main_Page.

Nick

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

Re: Noob jQuery AJAX question

tfleig
Yup. I read the JQuery section in the seaside book and I even had Firebug open when I noticed your email reply.

Thanks for your help.
TF

On Sun, Nov 14, 2010 at 1:16 PM, Nick Ager <[hidden email]> wrote:
Tony,
 
I'm new enough to this that it seems like magic to me...

In the following onChange event, Seaside somehow arranges that the callback block is executed with the serialized parameter before the AJAX script object is executed, which is of course exactly what I want.

Is there a set of rules that are used to determine in what order these things occur? Is this documented somewhere?

There's some documentation here: http://book.seaside.st/book/web-20/jquery

When I was experimenting with Seaside and JQuery I kept firebug open, examined the javascript that was generated and referred to the javascript JQuery documentation: http://docs.jquery.com/Main_Page.

Nick

_______________________________________________
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