Get the result of JS function

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

Get the result of JS function

Thomas Heniart
Hi everyone,

Is it possible to get the result after calling a JS function from Seaside

For exemple I have a function in a JS file with a function test() which return true,

Can we do something like
  result := html aMethod: 'test()'.
which execute my function and get the result as a String in result ?

Cheers,
Thomas

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

Re: Get the result of JS function

jtuchel
Thomas,

the JS function runs down in the web browser and returns its result locally. So there is no easy way to get the results back to the server, as far as I know. Calling the function can also only be accomplished down in the Browser, e.g. by using events line onLoad etc.

What we usually do in Kontolino is to send such results back to the server using an AJAX call.

It is not easy to provide sample code, because you don't exactly state how and when you want a function to be called and such.
So just a hint:

we ship down JS code that hooks into Document.onload() from our FileLibrary or external source (using html document addLoadScript:) and instead of simply returning results we send an AJAX call to the server to inform it about the results. The tricky part here is to give that script a callback name to call back to.
Please ask for more specific info.

HTH

Joachim


Am 22.09.15 um 07:57 schrieb Thomas Heniart:
Hi everyone,

Is it possible to get the result after calling a JS function from Seaside

For exemple I have a function in a JS file with a function test() which return true,

Can we do something like
  result := html aMethod: 'test()'.
which execute my function and get the result as a String in result ?

Cheers,
Thomas


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


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
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
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Get the result of JS function

Johan Brichau-2
In reply to this post by Thomas Heniart
Thomas,

You can use the jQuery binding in Seaside to easily return javascript values in ajax callbacks.
For example:

html
        button;
        onClick: (html jQuery ajax callback: [:value | Transcript show: value ] value: (html javascript call: ‘test’ withArguments: #()))
        with: ‘Call test’

The #callback:value: method passes the result of client-side expression to the server-side callback.
Mind that (as the method comment states), this only works for single literal Javascript object (String, Number, Boolean). If you want to pass more complex result values, you can use #callback:json: or write your own serialization if json serialization is not sufficient either.

Hope this answers your question,
Johan

> On 22 Sep 2015, at 07:57, Thomas Heniart <[hidden email]> wrote:
>
> Hi everyone,
>
> Is it possible to get the result after calling a JS function from Seaside
>
> For exemple I have a function in a JS file with a function test() which return true,
>
> Can we do something like
>   result := html aMethod: 'test()'.
> which execute my function and get the result as a String in result ?
>
> Cheers,
> Thomas
> _______________________________________________
> 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: Get the result of JS function

Thomas Heniart


2015-09-22 9:13 GMT+02:00 Johan Brichau <[hidden email]>:
Thomas,

You can use the jQuery binding in Seaside to easily return javascript values in ajax callbacks.
For example:

html
        button;
        onClick: (html jQuery ajax callback: [:value | Transcript show: value ] value: (html javascript call: ‘test’ withArguments: #()))
        with: ‘Call test’

I tried this but it doesn't work, nothing appeared in the Transcript like if the callback isn't triggered...
Maybe I forget something in the configuration of application
(WAAdmin register: self asApplicationAt: 'Test')
        addLibrary: JQDevelopmentLibrary;
        addLibraby: MyLibraryWithJsFiles

MyLibraryWithJsFiles contains just a js file with test() { return true; }
 

The #callback:value: method passes the result of client-side expression to the server-side callback.
Mind that (as the method comment states), this only works for single literal Javascript object (String, Number, Boolean). If you want to pass more complex result values, you can use #callback:json: or write your own serialization if json serialization is not sufficient either.

Hope this answers your question,
Johan


Thanks for your help,

Thomas


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

Re: Get the result of JS function

Thomas Heniart
I get this error when I load the page:
SyntaxError: expected expression, got '.'
and I don't know why :/
What could it be?


Cheers,
Thomas

2015-09-22 18:31 GMT+02:00 Thomas Heniart <[hidden email]>:


2015-09-22 9:13 GMT+02:00 Johan Brichau <[hidden email]>:
Thomas,

You can use the jQuery binding in Seaside to easily return javascript values in ajax callbacks.
For example:

html
        button;
        onClick: (html jQuery ajax callback: [:value | Transcript show: value ] value: (html javascript call: ‘test’ withArguments: #()))
        with: ‘Call test’

I tried this but it doesn't work, nothing appeared in the Transcript like if the callback isn't triggered...
Maybe I forget something in the configuration of application
(WAAdmin register: self asApplicationAt: 'Test')
        addLibrary: JQDevelopmentLibrary;
        addLibraby: MyLibraryWithJsFiles

MyLibraryWithJsFiles contains just a js file with test() { return true; }
 

The #callback:value: method passes the result of client-side expression to the server-side callback.
Mind that (as the method comment states), this only works for single literal Javascript object (String, Number, Boolean). If you want to pass more complex result values, you can use #callback:json: or write your own serialization if json serialization is not sufficient either.

Hope this answers your question,
Johan


Thanks for your help,

Thomas



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

Re: Get the result of JS function

Johan Brichau-2
In what file is the syntax error?

This is probably a syntax error in your javascript.

On 22 Sep 2015, at 19:21, Thomas Heniart <[hidden email]> wrote:

I get this error when I load the page:
SyntaxError: expected expression, got '.'
and I don't know why :/
What could it be?


Cheers,
Thomas

2015-09-22 18:31 GMT+02:00 Thomas Heniart <[hidden email]>:


2015-09-22 9:13 GMT+02:00 Johan Brichau <[hidden email]>:
Thomas,

You can use the jQuery binding in Seaside to easily return javascript values in ajax callbacks.
For example:

html
        button;
        onClick: (html jQuery ajax callback: [:value | Transcript show: value ] value: (html javascript call: ‘test’ withArguments: #()))
        with: ‘Call test’

I tried this but it doesn't work, nothing appeared in the Transcript like if the callback isn't triggered...
Maybe I forget something in the configuration of application
(WAAdmin register: self asApplicationAt: 'Test')
        addLibrary: JQDevelopmentLibrary;
        addLibraby: MyLibraryWithJsFiles

MyLibraryWithJsFiles contains just a js file with test() { return true; }
 

The #callback:value: method passes the result of client-side expression to the server-side callback.
Mind that (as the method comment states), this only works for single literal Javascript object (String, Number, Boolean). If you want to pass more complex result values, you can use #callback:json: or write your own serialization if json serialization is not sufficient either.

Hope this answers your question,
Johan


Thanks for your help,

Thomas


_______________________________________________
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: Get the result of JS function

Thomas Heniart
Error is in wqTest (:1:104), so I don't think that error is in my JS file which only contains
function test() {
  return true;
}

Really strange...


2015-09-22 19:35 GMT+02:00 Johan Brichau <[hidden email]>:
In what file is the syntax error?

This is probably a syntax error in your javascript.

On 22 Sep 2015, at 19:21, Thomas Heniart <[hidden email]> wrote:

I get this error when I load the page:
SyntaxError: expected expression, got '.'
and I don't know why :/
What could it be?


Cheers,
Thomas

2015-09-22 18:31 GMT+02:00 Thomas Heniart <[hidden email]>:


2015-09-22 9:13 GMT+02:00 Johan Brichau <[hidden email]>:
Thomas,

You can use the jQuery binding in Seaside to easily return javascript values in ajax callbacks.
For example:

html
        button;
        onClick: (html jQuery ajax callback: [:value | Transcript show: value ] value: (html javascript call: ‘test’ withArguments: #()))
        with: ‘Call test’

I tried this but it doesn't work, nothing appeared in the Transcript like if the callback isn't triggered...
Maybe I forget something in the configuration of application
(WAAdmin register: self asApplicationAt: 'Test')
        addLibrary: JQDevelopmentLibrary;
        addLibraby: MyLibraryWithJsFiles

MyLibraryWithJsFiles contains just a js file with test() { return true; }
 

The #callback:value: method passes the result of client-side expression to the server-side callback.
Mind that (as the method comment states), this only works for single literal Javascript object (String, Number, Boolean). If you want to pass more complex result values, you can use #callback:json: or write your own serialization if json serialization is not sufficient either.

Hope this answers your question,
Johan


Thanks for your help,

Thomas


_______________________________________________
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



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

Re: Get the result of JS function

Bob Arning-2
In reply to this post by Thomas Heniart
happens to me when I write js with my Smalltalk hat on. Periods instead of semicolons at the end of a statement.

On 9/22/15 1:21 PM, Thomas Heniart wrote:
I get this error when I load the page:
SyntaxError: expected expression, got '.'
and I don't know why :/
What could it be?


Cheers,
Thomas

2015-09-22 18:31 GMT+02:00 Thomas Heniart <[hidden email]>:


2015-09-22 9:13 GMT+02:00 Johan Brichau <[hidden email]>:
Thomas,

You can use the jQuery binding in Seaside to easily return javascript values in ajax callbacks.
For example:

html
        button;
        onClick: (html jQuery ajax callback: [:value | Transcript show: value ] value: (html javascript call: ‘test’ withArguments: #()))
        with: ‘Call test’

I tried this but it doesn't work, nothing appeared in the Transcript like if the callback isn't triggered...
Maybe I forget something in the configuration of application
(WAAdmin register: self asApplicationAt: 'Test')
        addLibrary: JQDevelopmentLibrary;
        addLibraby: MyLibraryWithJsFiles

MyLibraryWithJsFiles contains just a js file with test() { return true; }
 

The #callback:value: method passes the result of client-side expression to the server-side callback.
Mind that (as the method comment states), this only works for single literal Javascript object (String, Number, Boolean). If you want to pass more complex result values, you can use #callback:json: or write your own serialization if json serialization is not sufficient either.

Hope this answers your question,
Johan


Thanks for your help,

Thomas




_______________________________________________
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: Get the result of JS function

Johan Brichau-2
In reply to this post by Thomas Heniart
I think you will need to supply a bit more code or information.

Where is wqTest coming from?

On 22 Sep 2015, at 19:47, Thomas Heniart <[hidden email]> wrote:

Error is in wqTest (:1:104), so I don't think that error is in my JS file which only contains
function test() {
  return true;
}

Really strange...


2015-09-22 19:35 GMT+02:00 Johan Brichau <[hidden email]>:
In what file is the syntax error?

This is probably a syntax error in your javascript.

On 22 Sep 2015, at 19:21, Thomas Heniart <[hidden email]> wrote:

I get this error when I load the page:
SyntaxError: expected expression, got '.'
and I don't know why :/
What could it be?


Cheers,
Thomas

2015-09-22 18:31 GMT+02:00 Thomas Heniart <[hidden email]>:


2015-09-22 9:13 GMT+02:00 Johan Brichau <[hidden email]>:
Thomas,

You can use the jQuery binding in Seaside to easily return javascript values in ajax callbacks.
For example:

html
        button;
        onClick: (html jQuery ajax callback: [:value | Transcript show: value ] value: (html javascript call: ‘test’ withArguments: #()))
        with: ‘Call test’

I tried this but it doesn't work, nothing appeared in the Transcript like if the callback isn't triggered...
Maybe I forget something in the configuration of application
(WAAdmin register: self asApplicationAt: 'Test')
        addLibrary: JQDevelopmentLibrary;
        addLibraby: MyLibraryWithJsFiles

MyLibraryWithJsFiles contains just a js file with test() { return true; }
 

The #callback:value: method passes the result of client-side expression to the server-side callback.
Mind that (as the method comment states), this only works for single literal Javascript object (String, Number, Boolean). If you want to pass more complex result values, you can use #callback:json: or write your own serialization if json serialization is not sufficient either.

Hope this answers your question,
Johan


Thanks for your help,

Thomas


_______________________________________________
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


_______________________________________________
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: Get the result of JS function

Thomas Heniart
wqTest come from WQTest class
class side:
canBeRoot
    ^ true

initialize
    super initialize.
    (WAAdmin register: self asApplicationAt: 'wqTest')
        addLibrary: JQDevelopmentLibrary;
        addLibrary: WQTestFileLibrary


instance side:
renderContentOn: html
    html button
        onClick: (html jQuery ajax callback: [ :value | Transcript show: 'value' ] value: (html javascript call: 'test'));
        with: 'Call test'

And WQTestFileLibrary
 contains a single JS file with:

function test() {
  return true;
}

This a very small example just to see where the bug could come from


Thomas

2015-09-22 21:48 GMT+02:00 Johan Brichau <[hidden email]>:
I think you will need to supply a bit more code or information.

Where is wqTest coming from?

On 22 Sep 2015, at 19:47, Thomas Heniart <[hidden email]> wrote:

Error is in wqTest (:1:104), so I don't think that error is in my JS file which only contains
function test() {
  return true;
}

Really strange...


2015-09-22 19:35 GMT+02:00 Johan Brichau <[hidden email]>:
In what file is the syntax error?

This is probably a syntax error in your javascript.

On 22 Sep 2015, at 19:21, Thomas Heniart <[hidden email]> wrote:

I get this error when I load the page:
SyntaxError: expected expression, got '.'
and I don't know why :/
What could it be?


Cheers,
Thomas

2015-09-22 18:31 GMT+02:00 Thomas Heniart <[hidden email]>:


2015-09-22 9:13 GMT+02:00 Johan Brichau <[hidden email]>:
Thomas,

You can use the jQuery binding in Seaside to easily return javascript values in ajax callbacks.
For example:

html
        button;
        onClick: (html jQuery ajax callback: [:value | Transcript show: value ] value: (html javascript call: ‘test’ withArguments: #()))
        with: ‘Call test’

I tried this but it doesn't work, nothing appeared in the Transcript like if the callback isn't triggered...
Maybe I forget something in the configuration of application
(WAAdmin register: self asApplicationAt: 'Test')
        addLibrary: JQDevelopmentLibrary;
        addLibraby: MyLibraryWithJsFiles

MyLibraryWithJsFiles contains just a js file with test() { return true; }
 

The #callback:value: method passes the result of client-side expression to the server-side callback.
Mind that (as the method comment states), this only works for single literal Javascript object (String, Number, Boolean). If you want to pass more complex result values, you can use #callback:json: or write your own serialization if json serialization is not sufficient either.

Hope this answers your question,
Johan


Thanks for your help,

Thomas


_______________________________________________
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


_______________________________________________
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



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