[Seaside] Jquery Ajax confirm: callback problem

Johan Brichau johan at inceptive.be
Wed Jul 25 13:34:26 UTC 2012


Hi Joachim,

Sorry it did not work that easily. Strange that it worked on FF and not on Chrome but I could make it work just fine in both like this:

renderContentOn: html
	| id |
	html anchor 
		id: (id := html nextId);
		onClick: (html jQuery ajax
					confirm: 'Do you really want to replace me?';
					script: [:s| 	linkText := 'I am the replaced one'. 
								s << ((s jQuery id: id) replaceWith: [:h | self renderOn: h])]);
		with: linkText.

linkText is an instance variable of the component, first initialized like this:

initialize 
	super initialize.
	linkText := 'I am the original one'

Mind that #load is a specific ajax request that will replace the inner contents of the receiving jQuery selector with the rendering done by its 'html: aBlock' argument. 
It's not useful to launch it from within another ajax callback block, especially because you can more easily use a replaceWith: (or innerReplaceWith:). You *could* return a script that executes an ajax load, but that means 2 ajax callbacks (one for the delete + load script and one for the actual load of the new html). 

There are many ways to puzzle together ajax calls. An (untested) variant using an ajax load where only a single ajax callback occurs might be:

renderContentOn: html
	| id |
	html anchor 
		id: (id := html nextId);
		onClick: (html jQuery ajax
					confirm: 'Do you really want to replace me?';
					script: ((html jQuery id: id)  load html:[:h | linkText := 'I am the replaced one'. self renderOn: h]));
		with: linkText.

Obviously, you should insert your actual statements (deleteObject) where needed in the callback.

Hope this still helps you somewhat!

Cheers
Johan

On 23 Jul 2012, at 21:02, Joachim Tuchel wrote:

> Hi again,
> 
> I gave up on this and wrote a little jQuery plugin. It works on both Firefox and Chrome.
> This confirm: stuff took too much time to understand and test...
> Nevertheless, thank you for your help.
> 
> Joachim
> 
> 
> Am 23.07.12 14:33, schrieb Joachim Tuchel:
>> Paul, Johan,
>> 
>> so this is what my code looks like right now:
>> 
>> s jQuery ajax
>> 
>> confirm: 'Do you really want to delete this object?';
>> script: [:t|
>> self deleteObject: obj.
>> t << (t jQuery id: link id) load "link is the anchor tag"
>> html: [:q | self renderChildrenOn: q]]
>> 
>> 
>> Which is a mix of your suggestions. It does work perfectly on Firefox: I get asked if I want to delete, and only if I click OK the object is deleted and the list is re-rendered.
>> 
>> On Chrome, however, I get the confirmation dialog and it does nothing if I click cancel, but it also does nothing if I hit OK.
>> A breakpoint in #deleteObject: never fires. So it seems like the script: doesn't work on Chrome (which I cannot believe).
>> 
>> 
>> Joachim
>> 
>> 
>> 
>> 
>> Am 20.07.12 19:00, schrieb Paul DeBruicker:
>>> On 07/19/2012 11:22 PM, Joachim Tuchel (objektfabrik) wrote:
>>>> Unfortunately, it doesn't work for me. It leaves me with a blank page on
>>>> Chrome and a text-only page containing teh html of the complete page
>>>> re-rendered. Even if I replace the jQuery this with the concrete ID of
>>>> my list, it doesn't work.
>>>> 
>>>> Wouldn't a POST request reload the whole page anyways?
>>>> 
>>> 
>>> 
>>> Sorry that didn't work. I think Johan was right about my missing parens.
>>> 
>>> The ajax POST doesn't reload the whole page. It just sends the info to the server as a POST rather than GET which I'd thought was the thing to do if you were deleting something and a DELETE wasn't a supported part of the library.
>>> 
>>> 
>>> See: http://www.cs.tut.fi/~jkorpela/forms/methods.html & http://stackoverflow.com/questions/715335/get-vs-post-in-ajax#715355
>>> 
>>> jQuery's ajax post docs are here: http://docs.jquery.com/Post
>>> 
>>> 
>>> I'll try to think of why else its not correct and get back to you.
>> 
>> 
>> 
>> _______________________________________________
>> seaside mailing list
>> seaside at lists.squeakfoundation.org
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> 
> -- 
> -- 
> ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel          mailto:jtuchel at objektfabrik.de Fliederweg 1                         http://www.objektfabrik.de
> D-71640 Ludwigsburg 		     http://joachimtuchel.wordpress.com
> Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1
> 
> 
> 
> 
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



More information about the seaside mailing list