[Seaside] How to have a ajax handler?

Johan Brichau johan at inceptive.be
Wed Jul 9 20:31:52 UTC 2014


Hi Mariano,

I assume that the JS library takes an option parameter to specify the url of an ajax callback?
There are (at least) three different way to solve this:

1. use the url of an ajax callback created during Seaside rendering. This is how to do that:

	urlForXHRAction: aBlock
		"Answer an action URL that will evaluate aBlock when it is requested."
		^ renderContext actionUrl withField: (renderContext callbacks store: (JSAjaxCallback on: aBlock))

	urlForJsonCallback: aCallback 
		 ^ (self urlForXHRAction: [ self requestContext respond: [:response | 
				 response 
					 doNotCache; 
					 contentType: WAMimeType applicationJson; 
					 nextPutAll: (WAJsonCanvas builder render: aCallback)]])

I copied the above from an image where I use Seaside 3.1.x. 
If you use 3.0.x, you need a different json callback. Let me know if you need that.
You can use it in your rendering method as follows:

	url := self urlForJsonCallback: [:json | json array:[ ... ] ]


2. use a RestfulComponentFilter from Seaside-REST.

You can define a filter that captures (REST) urls send back to your application's session. 
If you define a filter, you would pass the url that is captured by the filter to the JS library.

More info can be found in the Seaside book: http://book.seaside.st/book/advanced/restful/handler-filter

- use a separate (REST) api

In that case, you would pass a full url to another service (possibly served by the same Smalltalk image) to the JS lib.


Hope this helps!
Johan


On 09 Jul 2014, at 15:57, Mariano Martinez Peck <marianopeck at gmail.com> wrote:

> Hi guys,
> 
> Maybe the subject of the email is not the most accurate. What I need is the following. From seaside, I am calling a JS library using "html script: 'xxx' ". Now, that JS libs provides me a feature in which it can do an AJAX request to the "url/someAPI" and send some JSON (what I need).
> 
> When I do an ajax request from within seaside I can easily attach a callback. However, in this case, I don't know how to do that. What I need is a callback associated to url/someAPI and I need to read the JSON sent in that ajax request.
> 
> Any idea how can I do this?
> 
> Thanks in advance,  
> 
> -- 
> Mariano
> http://marianopeck.wordpress.com
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



More information about the seaside mailing list