[Seaside] Javascript calls through jQuery

Johan Brichau johan at inceptive.be
Sun Mar 2 21:00:55 UTC 2014


Hi Esteban,

I think there is something missing in the JQuery-Seaside binding here.
imho, what you need is a #json: value-rendering callback, in the style of the #script:, #html: or #text: callbacks.

In Seaside 3.0, the following would work:

JQGetJson>>json: aBlock
	"Defines a json rendering callback."

	self dataType: 'application/json'.
	self respond: [ :response |
		response
			doNotCache;
			contentType: (WAMimeType applicationJson 
				charset: self requestContext handler charSet).
		aBlock value: response stream ]

Your example would then become:

(html jQuery ajax
		serializeForm;
		onComplete: (
   			html jQuery getJson
        			json: [:str | ... ];
        			onSuccess: 'myJsFileFunction(arguments[0])' ) );

However, with the new WAJsonCanvas in Seaside3.1, we would prefer to get a JSON canvas as the argument to the #json: callback. 
In the code above, it's the response stream.
I think it should be possible, and I will take a look for that.

Johan

On 02 Mar 2014, at 19:51, Esteban A. Maringolo <emaringolo at gmail.com> wrote:

> I was reading that part of the book before sending the mail. But there
> are several "ToDo" in the AJAX parts of the book :)
> 
> The http://demo.seaside.st/javascript/jquery/loadexternaljson #getJson
> jquery object could do the trick. But it depends on a static URL.
> 
> I want to get the JSON response from the URL of the callback (whatever
> black magic happens behind).
> 
> I was thinking in something like:
> 
> html jQuery ajax
>  serializeForm;
>  onComplete: (
>     html jQuery getJson
>         callback: [ self answerJsonWithNewFormParameters ];
>         onSuccess: 'myJsFileFunction(arguments[0])' )
> 
> 
> The problem is that I'm in the learning curve part where I'm fighting
> against not understanding how it works instead of fighting why it
> doesn't work :)
> 
> Regards!
> 
> Esteban A. Maringolo
> 
> 
> 2014-03-02 15:29 GMT-03:00 Sven Van Caekenberghe <sven at stfx.eu>:
>> I am a beginner with the Seaside jQuery codebase myself, but I do like it.
>> 
>> I guess you know about http://book.seaside.st/book/web-20/jquery ?
>> 
>> For the more advanced stuff, you will have to either find it in the image, on the internet, in particular on this list, or ask in small increments.
>> 
>> On 02 Mar 2014, at 19:13, Esteban A. Maringolo <emaringolo at gmail.com> wrote:
>> 
>>> I'm bumping this.
>>> 
>>> Today I have a set of functions in a JavaScript file querying a
>>> RESTFilter'ed component at a fixed URL. The REST path will return a
>>> list of elements in a JSON response, which is passed to other js
>>> function in the beforementioned js file.
>>> 
>>> I want to move as much as I can from the JS file to Seaside, because
>>> now I need to add certain parameters to the request, and I thought it
>>> would be simpler to do it with Seaside.
>>> 
>>> What I need is to be able to do is:
>>> 1. fill a form (a set of filters) which will send an ajax call to the
>>> seaside component
>>> 2. The seaside component will process the form and decide what to
>>> return (the JSON response)
>>> 3. Once the response arrives back at the client side, the json
>>> response must be passed to another JS function as an argument
>>> 4. Must repeat item #3 every n seconds.
>>> 
>>> I can do this on the JS side, but I still don't get how the whole
>>> jQuery machinery works in Seaside.
>>> Seems to be utter powerful, but not as straightforward as simply
>>> writing the JS :)
>>> 
>>> 
>>> Regards!
>>> 
>>> Esteban A. Maringolo
>>> 
>>> 
>>> 2014-02-18 10:05 GMT-03:00 Esteban A. Maringolo <emaringolo at gmail.com>:
>>>> Is there a way I can perform an AJAX call to get a JSON response and
>>>> pass it to a JavaScript function?
>>>> 
>>>> Now I'm gluing everying externally by means of a JS file, but the AJAX
>>>> calls are outside of the Seaside session (REST Filter), and I'd like
>>>> to get everything in the same session.
>>>> 
>>>> Thanks in advance,
>>>> 
>>>> Esteban A. Maringolo
>>> _______________________________________________
>>> seaside mailing list
>>> seaside at lists.squeakfoundation.org
>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>> 
>> _______________________________________________
>> seaside mailing list
>> seaside at lists.squeakfoundation.org
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



More information about the seaside mailing list