Hi,
I have spent several hours in the following problem: I want to use a list of names in Pharo which I get from amazon S3. But it is not a aws problem but a problem of understanding how to use callbacks/asynchronus code and return values. This is a simplified version for describing the problem. Pressing the button "testing" evaluates the Javascript code below. The result, I want to use in Pharo is the result which is at *1*. But the method immediately returns the result at *2*, because it dose not wait for the function to be completed. This is more a javascript question but perhaps someone had a similar problem. Perhaps someone has an idea. I already tried with promises but did not succeed. Sabine renderTestOn: html html html: ''. html div onClick: (html jQuery ajax callback: [ :var | var inspect ] value: (JSStream on: 'getS3Data()')); with: 'testing' -- Sent from: http://forum.world.st/Seaside-General-f86180.html _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Hi Sabine,
i don’t know what exactly you mean with 1 and 2 but i assume getS3Data() returns immediately and its result is sent to the server. If getS3Data() performs an asynchronous call, the method is pretty quick and doesn’t block.
What you need to do is something like this (from the jQuery website):
Kind Regards
Karsten
Am 21. November 2018 um 14:57:04, Sabine Manaa ([hidden email]) schrieb:
_______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
In reply to this post by Sabine Manaa
Hi Sabine,
I assume you need to pass a callback function as argument to `getS3Data` that will be called when the result data is ready? The following wraps the Ajax call in a function with one argument and passes it as an argument to `getS3Data’. Invoking the function with a value invokes the ajax request with the given value. html javascript call: 'getS3Data' with: ((html jQuery ajax callback: [ :var | var inspect ] value: (html javascript alias: 'value')) asFunction: #(value)) Does this come close? cheers Johan > On 21 Nov 2018, at 14:56, Sabine Manaa <[hidden email]> wrote: > > Hi, > > I have spent several hours in the following problem: I want to use a list of > names in Pharo which I get from amazon S3. But it is not a aws problem but a > problem of understanding how to use callbacks/asynchronus code and return > values. This is a simplified version for describing the problem. Pressing > the button "testing" evaluates the Javascript code below. The result, I want > to use in Pharo is the result which is at *1*. But the method immediately > returns the result at *2*, because it dose not wait for the function to be > completed. This is more a javascript question but perhaps someone had a > similar problem. > Perhaps someone has an idea. I already tried with promises but did not > succeed. > > Sabine > > > renderTestOn: html > html > html: > ''. > > html div > onClick: > (html jQuery ajax callback: [ :var | var inspect ] value: (JSStream on: > 'getS3Data()')); > with: 'testing' > > > > -- > Sent from: http://forum.world.st/Seaside-General-f86180.html > _______________________________________________ > 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 |
Yesterday I was asking this question and also asked in discord.
In discord I wrote today with Johan Brichau. He gave the solution to me and I want to share it here because when I have a problem, I often look here. The solution was like this (I remove the script brackets for the mailing list). Thanks a lot, Johan! The task is to call a javascript method and return a result from somewhere in the javascript. Clicking on the button opens an inspector in the smalltalk image. renderTestOn: html html html: 'script function getS3Data(callback) { callback(''this goes back to the smalltalk image'' ); } /script '. html button onClick: ((html javascript alias: 'getS3Data') apply: {((html jQuery ajax callback: [ :var | var inspect ] value: (html javascript alias: 'value')) asFunction: #(value))}); with: 'tedt' -- Sent from: http://forum.world.st/Seaside-General-f86180.html _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Free forum by Nabble | Edit this page |