From Smalltalk to JavaScript

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

From Smalltalk to JavaScript

horrido
Okay, obviously, I am not grokking this whole JavaScript interfacing thing. I've got to find a way to wrap my head around it.

According to this webpage: http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax

I can use jQuery's beforeSend callback to add a HTTP header with authentication information:

beforeSend: function (xhr) {
    xhr.setRequestHeader ("Authorization", "Basic XXXXXX");
},

So in my Amber code, I tried this:

jQuery = JQuery current.
jQuery getJSON: 'some-url'
    beforeSend: [:xhr | |enc| enc = window btoa: 'usr:pwd'.
        xhr setRequestHeader: 'Authorization' put: 'Basic ',enc]
    onSuccess: [:jsonData | "do something with jsonData"].

It does not understand btoa:,  even though the following works perfectly in the Workspace:

window btoa: 'usr:pwd'

When I get rid of the btoa stuff, it complains that it does not understand setRequestHeader:.

I've looked at this: https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back

And it confuses me. What am I doing wrong???

Btw, I'm not having much luck with '< >', either.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: From Smalltalk to JavaScript

Amber Smalltalk mailing list
Hi Richard,

not knowing if your code would work, I would still think you have to change your assignments from "=" to ":="

jQuery := JQuery current.
jQuery getJSON: 'some-url'
    beforeSend: [:xhr | |enc| enc := window btoa: 'usr:pwd'.
        xhr setRequestHeader: 'Authorization' put: 'Basic ',enc]
    onSuccess: [:jsonData | "do something with jsonData"].

Sebastian


On 2015-05-29 4:21 PM, Richard Eng wrote:
Okay, obviously, I am not grokking this whole JavaScript interfacing thing. I've got to find a way to wrap my head around it.


I can use jQuery's beforeSend callback to add a HTTP header with authentication information:

beforeSend: function (xhr) {
    xhr.setRequestHeader ("Authorization", "Basic XXXXXX");
},

So in my Amber code, I tried this:

jQuery = JQuery current.
jQuery getJSON: 'some-url'
    beforeSend: [:xhr | |enc| enc = window btoa: 'usr:pwd'.
        xhr setRequestHeader: 'Authorization' put: 'Basic ',enc]
    onSuccess: [:jsonData | "do something with jsonData"].

It does not understand btoa:,  even though the following works perfectly in the Workspace:

window btoa: 'usr:pwd'

When I get rid of the btoa stuff, it complains that it does not understand setRequestHeader:.


And it confuses me. What am I doing wrong???

Btw, I'm not having much luck with '< >', either.
--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: From Smalltalk to JavaScript

horrido
Say, you're right! Stupid typo.

Okay, but now, it doesn't recognize setRequestHeader:put:. (If I get rid of put:, it doesn't recognize setRequestHeader:, so apparently it's not mapping setRequestHeader from JS.


On Friday, 29 May 2015 20:18:30 UTC-4, HCSebastian wrote:
Hi Richard,

not knowing if your code would work, I would still think you have to change your assignments from "=" to ":="

jQuery := JQuery current.
jQuery getJSON: 'some-url'
    beforeSend: [:xhr | |enc| enc := window btoa: 'usr:pwd'.
        xhr setRequestHeader: 'Authorization' put: 'Basic ',enc]
    onSuccess: [:jsonData | "do something with jsonData"].

Sebastian


On 2015-05-29 4:21 PM, Richard Eng wrote:
Okay, obviously, I am not grokking this whole JavaScript interfacing thing. I've got to find a way to wrap my head around it.

According to this webpage: <a href="http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;">http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax

I can use jQuery's beforeSend callback to add a HTTP header with authentication information:

beforeSend: function (xhr) {
    xhr.setRequestHeader ("Authorization", "Basic XXXXXX");
},

So in my Amber code, I tried this:

jQuery = JQuery current.
jQuery getJSON: 'some-url'
    beforeSend: [:xhr | |enc| enc = window btoa: 'usr:pwd'.
        xhr setRequestHeader: 'Authorization' put: 'Basic ',enc]
    onSuccess: [:jsonData | "do something with jsonData"].

It does not understand btoa:,  even though the following works perfectly in the Workspace:

window btoa: 'usr:pwd'

When I get rid of the btoa stuff, it complains that it does not understand setRequestHeader:.

I've looked at this: <a href="https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;">https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back

And it confuses me. What am I doing wrong???

Btw, I'm not having much luck with '< >', either.
--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="oWI5A4FTEcQJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">amber-lang+...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: From Smalltalk to JavaScript

Amber Smalltalk mailing list
In reply to this post by horrido
Hmmm.....

I jjust read that getJson is a shorthand and one can't set additional options...

Did you already consider to do it this way?
----------------------------------
get: aUrlString  do: aBlock onError: errorBlock

    jQuery ajax: aUrlString 
        options: #{
            'type' -> 'GET'.
            'contentType' -> 'application/json'.
            'beforeSend' -> [:xhr | |enc| enc = window btoa: 'usr:pwd'.
        xhr setRequestHeader: 'Authorization' with: 'Basic ',enc].
            'complete' -> [:res |
                    res status = 200
                        ifTrue: [aBlock value: res responseText]
                        ifFalse: [errorBlock value: res responseText]
}
---------------------------------------

or something like:

 jQuery = JQuery current.

 jQuery ajaxSetup: #{
        'headers' -> #{
       
    'Authorization' : 'Basic faskd52352rwfsdfs';
        }
    }.

 jQuery getJSON: 'some-url'
    onSuccess: [:jsonData | "do something with jsonData"].


Just guessing the seperators, I still struggle with the right Array {} syntax.

Sebastian

On 2015-05-29 4:21 PM, Richard Eng wrote:
Okay, obviously, I am not grokking this whole JavaScript interfacing thing. I've got to find a way to wrap my head around it.


I can use jQuery's beforeSend callback to add a HTTP header with authentication information:

beforeSend: function (xhr) {
    xhr.setRequestHeader ("Authorization", "Basic XXXXXX");
},

So in my Amber code, I tried this:

jQuery = JQuery current.
jQuery getJSON: 'some-url'
    beforeSend: [:xhr | |enc| enc = window btoa: 'usr:pwd'.
        xhr setRequestHeader: 'Authorization' put: 'Basic ',enc]
    onSuccess: [:jsonData | "do something with jsonData"].

It does not understand btoa:,  even though the following works perfectly in the Workspace:

window btoa: 'usr:pwd'

When I get rid of the btoa stuff, it complains that it does not understand setRequestHeader:.


And it confuses me. What am I doing wrong???

Btw, I'm not having much luck with '< >', either.
--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: From Smalltalk to JavaScript

Herby Vojčík
As for `window btoa: 'foo'`, it is preferable not to use `window` to access globals, but instead use them directly as in `btoa value: 'foo'`.

As already mentioned, there was wrong assignment in your code (I would not use assignment at all and write `JQuery current foo: 'bar'`, but it's just my preference).

Otherwise, there should be no problems with using JS calls - though for simplicity I always used single-arg ajax: #{ 'url' -> 'baz'. ... } send (and instead of setting callbacks in options, which is IIRC deprecated, I used done: and friends on the result of ajax: send).

Herby

Dňa 30. mája 2015 4:02:36 CEST používateľ 'Sebastian Heidbrink' via amber-lang <[hidden email]> napísal:
Hmmm.....

I jjust read that getJson is a shorthand and one can't set additional options...

Did you already consider to do it this way?
----------------------------------
get: aUrlString  do: aBlock onError: errorBlock

    jQuery ajax: aUrlString 
        options: #{
            'type' -> 'GET'.
            'contentType' -> 'application/json'.
            'beforeSend' -> [:xhr | |enc| enc = window btoa: 'usr:pwd'.
        xhr setRequestHeader: 'Authorization' with: 'Basic ',enc].
            'complete' -> [:res |
                    res status = 200
                        ifTrue: [aBlock value: res responseText]
                        ifFalse: [errorBlock value: res responseText]
}
---------------------------------------

or something like:

 jQuery = JQuery current.

 jQuery ajaxSetup: #{
        'headers' -> #{
       
    'Authorization' : 'Basic faskd52352rwfsdfs';
        }
    }.

 jQuery getJSON: 'some-url'
    onSuccess: [:jsonData | "do something with jsonData"].


Just guessing the seperators, I still struggle with the right Array {} syntax.

Sebastian

On 2015-05-29 4:21 PM, Richard Eng wrote:
Okay, obviously, I am not grokking this whole JavaScript interfacing thing. I've got to find a way to wrap my head around it.


I can use jQuery's beforeSend callback to add a HTTP header with authentication information:

beforeSend: function (xhr) {
    xhr.setRequestHeader ("Authorization", "Basic XXXXXX");
},

So in my Amber code, I tried this:

jQuery = JQuery current.
jQuery getJSON: 'some-url'
    beforeSend: [:xhr | |enc| enc = window btoa: 'usr:pwd'.
        xhr setRequestHeader: 'Authorization' put: 'Basic ',enc]
    onSuccess: [:jsonData | "do something with jsonData"].

It does not understand btoa:,  even though the following works perfectly in the Workspace:

window btoa: 'usr:pwd'

When I get rid of the btoa stuff, it complains that it does not understand setRequestHeader:.


And it confuses me. What am I doing wrong???

Btw, I'm not having much luck with '< >', either.
--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: From Smalltalk to JavaScript

horrido
Okay, I'm trying to follow your suggestions. This works:

JQuery current getJSON: 'https://miramar21.com/tut_server/default/api/verify/person/[hidden email]/Prometheus'
onSuccess: [:jsonData | alert value: 'verified is ',(jsonData at: 'verified')].

But when I try to convert to using the ajax call:

JQuery current ajax: #{'type' -> 'GET'.
'url' -> 'https://miramar21.com/tut_server/default/api/verify/person/[hidden email]/Prometheus'.
'dataType' -> 'json'}
onSuccess: [:jsonData | alert value: 'verified is ',(jsonData at: 'verified')].

onSuccess: is never executed. I don't understand to what class onSuccess: belongs; it doesn't appear to be part of jQuery.

I've never heard of done:.


On Saturday, 30 May 2015 00:56:43 UTC-4, Herby wrote:
As for `window btoa: 'foo'`, it is preferable not to use `window` to access globals, but instead use them directly as in `btoa value: 'foo'`.

As already mentioned, there was wrong assignment in your code (I would not use assignment at all and write `JQuery current foo: 'bar'`, but it's just my preference).

Otherwise, there should be no problems with using JS calls - though for simplicity I always used single-arg ajax: #{ 'url' -> 'baz'. ... } send (and instead of setting callbacks in options, which is IIRC deprecated, I used done: and friends on the result of ajax: send).

Herby

Dňa 30. mája 2015 4:02:36 CEST používateľ 'Sebastian Heidbrink' via amber-lang <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="zdUsE3TxNPsJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">amber...@...> napísal:
Hmmm.....

I jjust read that getJson is a shorthand and one can't set additional options...

Did you already consider to do it this way?
----------------------------------
get: aUrlString  do: aBlock onError: errorBlock

    jQuery ajax: aUrlString 
        options: #{
            'type' -> 'GET'.
            'contentType' -> 'application/json'.
            'beforeSend' -> [:xhr | |enc| enc = window btoa: 'usr:pwd'.
        xhr setRequestHeader: 'Authorization' with: 'Basic ',enc].
            'complete' -> [:res |
                    res status = 200
                        ifTrue: [aBlock value: res responseText]
                        ifFalse: [errorBlock value: res responseText]
}
---------------------------------------

or something like:

 jQuery = JQuery current.

 jQuery ajaxSetup: #{
        'headers' -> #{
       
    'Authorization' : 'Basic faskd52352rwfsdfs';
        }
    }.

 jQuery getJSON: 'some-url'
    onSuccess: [:jsonData | "do something with jsonData"].


Just guessing the seperators, I still struggle with the right Array {} syntax.

Sebastian

On 2015-05-29 4:21 PM, Richard Eng wrote:
Okay, obviously, I am not grokking this whole JavaScript interfacing thing. I've got to find a way to wrap my head around it.

According to this webpage: <a href="http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;">http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax

I can use jQuery's beforeSend callback to add a HTTP header with authentication information:

beforeSend: function (xhr) {
    xhr.setRequestHeader ("Authorization", "Basic XXXXXX");
},

So in my Amber code, I tried this:

jQuery = JQuery current.
jQuery getJSON: 'some-url'
    beforeSend: [:xhr | |enc| enc = window btoa: 'usr:pwd'.
        xhr setRequestHeader: 'Authorization' put: 'Basic ',enc]
    onSuccess: [:jsonData | "do something with jsonData"].

It does not understand btoa:,  even though the following works perfectly in the Workspace:

window btoa: 'usr:pwd'

When I get rid of the btoa stuff, it complains that it does not understand setRequestHeader:.

I've looked at this: <a href="https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;">https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back

And it confuses me. What am I doing wrong???

Btw, I'm not having much luck with '< >', either.
--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="zdUsE3TxNPsJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">amber-lang+...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: From Smalltalk to JavaScript

Herby Vojčík


Richard Eng wrote:

> Okay, I'm trying to follow your suggestions. This works:
>
> JQuery current getJSON:
> 'https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@.../Prometheus'
> onSuccess: [:jsonData | alert value: 'verified is ',(jsonData at:
> 'verified')].
>
> But when I try to convert to using the ajax call:
>
> JQuery current ajax: #{'type' -> 'GET'.
> 'url' ->
> 'https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@.../Prometheus'.
> 'dataType' -> 'json'}
> onSuccess: [:jsonData | alert value: 'verified is ',(jsonData at:
> 'verified')].
>
> onSuccess: is never executed. I don't understand to what class
> onSuccess: belongs; it doesn't appear to be part of jQuery.

???
I don't get this sentence and question in it at all.

>
> I've never heard of done:.

done, fail, always. Look up jQuery.ajax docs page.

>
>
> On Saturday, 30 May 2015 00:56:43 UTC-4, Herby wrote:
>
>     As for `window btoa: 'foo'`, it is
preferable not to use `window`

>     to access globals, but instead use them directly as in `btoa
>     value: 'foo'`.
>
>     As already mentioned, there was wrong assignment in your code (I
>     would not use assignment at all and write `JQuery current foo:
>     'bar'`, but it's just my preference).
>
>     Otherwise, there should be no problems with using JS calls -
>     though for simplicity I always used single-arg ajax: #{ 'url' ->
>     'baz'. ... } send (and instead of setting callbacks in options,
>     which is IIRC deprecated, I used done: and friends on the result
>     of ajax: send).
>
>     Herby
>
>     Dňa 30. mája 2015 4:02:36 CEST používateľ 'Sebastian Heidbrink'
>     via amber-lang <[hidden email] <javascript:>> napísal:
>
>         Hmmm.....
>
>         I jjust read that getJson is a shorthand and one can't set
>         additional options...
>
>         Did you already consider to do it this way?
>         ---------------------------
-------

>         get: aUrlString do: aBlock onError: errorBlock
>
>         jQuery ajax: aUrlString
>         options: #{
>         'type' -> 'GET'.
>         'contentType' -> 'application/json'.
>         'beforeSend' -> [:xhr | |enc| enc = window btoa: 'usr:pwd'.
>
>             xhr setRequestHeader: 'Authorization' with: 'Basic ',enc].
>
>         'complete' -> [:res |
>         res status = 200
>         ifTrue: [aBlock value: res responseText]
>         ifFalse: [errorBlock value: res responseText]
>         }
>         ---------------------------------------
>
>         or something like:
>
>         jQuery = JQuery current.
>
>         jQuery ajaxSetup: #{
>         'headers' -> #{
>         |'Authorization':'Basic faskd52352rwfsdfs'|;
>         ||}
>         }.
>
>         jQuery getJSON: 'some-url'
>
>             onSuccess: [:jsonData | "do something with jsonData"].
>
>
>
>         |Just guessing the seperators, I still struggle with the right
>         Array {} s
yntax.

>
>         Sebastian
>         |
>         On 2015-05-29 4:21 PM, Richard Eng wrote:
>>         Okay, obviously, I am not grokking this whole JavaScript
>>         interfacing thing. I've got to find a way to wrap my head
>>         around it.
>>
>>         According to this webpage:
>>         http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax
>>         <http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax>
>>
>>         I can use jQuery's /beforeSend/ callback to add a HTTP header
>>         with authentication information:
>>
>>             beforeSend: function (xhr) {
>>             xhr.setRequestHeader ("Authorization", "Basic XXXXXX");
>>             },
>>
>>
>>         So in my Amber code, I tried this:
>>
>>             jQuery = JQuery current.
>>             jQuery getJSON: 'some-url'
>>
>>             beforeSend: [:xhr | |enc| enc = window btoa: 'usr:pwd'.
>>
>>             xhr setRequestHead
er: 'Authorization' put: 'Basic ',enc]

>>
>>             onSuccess: [:jsonData | "do something with jsonData"].
>>
>>
>>         It does not understand btoa:, even though the following works
>>         perfectly in the Workspace:
>>
>>             window btoa: 'usr:pwd'
>>
>>
>>         When I get rid of the btoa stuff, it complains that it does
>>         not understand setRequestHeader:.
>>
>>         I've looked at this:
>>         https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back
>>         <https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back>
>>
>>         And it confuses me. What am I doing wrong???
>>
>>         Btw, I'm not having much luck with '< >', either.
>>         --
>>         You received this message because you are subscribed to the
>>         Google Groups "amber-lang" group.
>>         To unsubscribe from this group and stop receiving emails from
>>         it, send an email to amber-lang+
...@googlegroups.com

>>         <javascript:>.
>>         For more options, visit https://groups.google.com/d/optout
>>         <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "amber-lang" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [hidden email]
> <mailto:[hidden email]>.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: From Smalltalk to JavaScript

Herby Vojčík
In reply to this post by horrido


Richard Eng wrote:
> I've looked at this:
> https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back
>
> And it confuses me. What am I doing wrong???

Well, the fact is, you just MUST understand this (you can try to reword
it, if you think it can be done better, it's a wiki). Until you don't
get it, just reread it over and over until you do. I had the impression
the examples that are there cover all possibilities for understanding it
by example, if it's not the case, help with fixing it.

This is in fact very important part, as Amber is aimed at "take JS
library for the task and use it" solutions.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: From Smalltalk to JavaScript

horrido
In reply to this post by Herby Vojčík
Apparently, I'm not coding the ajax call correctly, because onSuccess: is not executed, i.e., I don't get an alert popup. When I used getJSON:, I did get an alert popup. So why isn't ajax: working?

As for onSuccess:, my question is whether it's associated with jQuery. jQuery has a 'success' callback, but it doesn't seem to take a parameter (i.e., the json result). onSuccess: does have a json result parameter. Ultimately, my question is, how do I obtain the json result from the ajax call?

On Saturday, 30 May 2015 08:50:59 UTC-4, Herby wrote:


Richard Eng wrote:

> Okay, I'm trying to follow your suggestions. This works:
>
> JQuery current getJSON:
> '<a href="https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@gmail.com/Prometheus" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmiramar21.com%2Ftut_server%2Fdefault%2Fapi%2Fverify%2Fperson%2Fhorrido.hobbies%40gmail.com%2FPrometheus\46sa\75D\46sntz\0751\46usg\75AFQjCNEF8Z2VKQJtTEMMKk3Ac3jVPyqkUQ';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmiramar21.com%2Ftut_server%2Fdefault%2Fapi%2Fverify%2Fperson%2Fhorrido.hobbies%40gmail.com%2FPrometheus\46sa\75D\46sntz\0751\46usg\75AFQjCNEF8Z2VKQJtTEMMKk3Ac3jVPyqkUQ';return true;">https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@gmail.com/Prometheus'
> onSuccess: [:jsonData | alert value: 'verified is ',(jsonData at:
> 'verified')].
>
> But when I try to convert to using the ajax call:
>
> JQuery current ajax: #{'type' -> 'GET'.
> 'url' ->
> '<a href="https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@gmail.com/Prometheus" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmiramar21.com%2Ftut_server%2Fdefault%2Fapi%2Fverify%2Fperson%2Fhorrido.hobbies%40gmail.com%2FPrometheus\46sa\75D\46sntz\0751\46usg\75AFQjCNEF8Z2VKQJtTEMMKk3Ac3jVPyqkUQ';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmiramar21.com%2Ftut_server%2Fdefault%2Fapi%2Fverify%2Fperson%2Fhorrido.hobbies%40gmail.com%2FPrometheus\46sa\75D\46sntz\0751\46usg\75AFQjCNEF8Z2VKQJtTEMMKk3Ac3jVPyqkUQ';return true;">https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@gmail.com/Prometheus'.
> 'dataType' -> 'json'}
> onSuccess: [:jsonData | alert value: 'verified is ',(jsonData at:
> 'verified')].
>
> onSuccess: is never executed. I don't understand to what class
> onSuccess: belongs; it doesn't appear to be part of jQuery.

???
I don't get this sentence and question in it at all.

>
> I've never heard of done:.

done, fail, always. Look up jQuery.ajax docs page.

>
>
> On Saturday, 30 May 2015 00:56:43 UTC-4, Herby wrote:
>
>     As for `window btoa: 'foo'`, it is
preferable not to use `window`

>     to access globals, but instead use them directly as in `btoa
>     value: 'foo'`.
>
>     As already mentioned, there was wrong assignment in your code (I
>     would not use assignment at all and write `JQuery current foo:
>     'bar'`, but it's just my preference).
>
>     Otherwise, there should be no problems with using JS calls -
>     though for simplicity I always used single-arg ajax: #{ 'url' ->
>     'baz'. ... } send (and instead of setting callbacks in options,
>     which is IIRC deprecated, I used done: and friends on the result
>     of ajax: send).
>
>     Herby
>
>     Dňa 30. mája 2015 4:02:36 CEST používateľ 'Sebastian Heidbrink'
>     via amber-lang <[hidden email] <javascript:>> napísal:
>
>         Hmmm.....
>
>         I jjust read that getJson is a shorthand and one can't set
>         additional options...
>
>         Did you already consider to do it this way?
>         ---------------------------
-------

>         get: aUrlString do: aBlock onError: errorBlock
>
>         jQuery ajax: aUrlString
>         options: #{
>         'type' -> 'GET'.
>         'contentType' -> 'application/json'.
>         'beforeSend' -> [:xhr | |enc| enc = window btoa: 'usr:pwd'.
>
>             xhr setRequestHeader: 'Authorization' with: 'Basic ',enc].
>
>         'complete' -> [:res |
>         res status = 200
>         ifTrue: [aBlock value: res responseText]
>         ifFalse: [errorBlock value: res responseText]
>         }
>         ---------------------------------------
>
>         or something like:
>
>         jQuery = JQuery current.
>
>         jQuery ajaxSetup: #{
>         'headers' -> #{
>         |'Authorization':'Basic faskd52352rwfsdfs'|;
>         ||}
>         }.
>
>         jQuery getJSON: 'some-url'
>
>             onSuccess: [:jsonData | "do something with jsonData"].
>
>
>
>         |Just guessing the seperators, I still struggle with the right
>         Array {} s
yntax.

>
>         Sebastian
>         |
>         On 2015-05-29 4:21 PM, Richard Eng wrote:
>>         Okay, obviously, I am not grokking this whole JavaScript
>>         interfacing thing. I've got to find a way to wrap my head
>>         around it.
>>
>>         According to this webpage:
>>         <a href="http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;">http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax
>>         <<a href="http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;">http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax>
>>
>>         I can use jQuery's /beforeSend/ callback to add a HTTP header
>>         with authentication information:
>>
>>             beforeSend: function (xhr) {
>>             xhr.setRequestHeader ("Authorization", "Basic XXXXXX");
>>             },
>>
>>
>>         So in my Amber code, I tried this:
>>
>>             jQuery = JQuery current.
>>             jQuery getJSON: 'some-url'
>>
>>             beforeSend: [:xhr | |enc| enc = window btoa: 'usr:pwd'.
>>
>>             xhr setRequestHead
er: 'Authorization' put: 'Basic ',enc]

>>
>>             onSuccess: [:jsonData | "do something with jsonData"].
>>
>>
>>         It does not understand btoa:, even though the following works
>>         perfectly in the Workspace:
>>
>>             window btoa: 'usr:pwd'
>>
>>
>>         When I get rid of the btoa stuff, it complains that it does
>>         not understand setRequestHeader:.
>>
>>         I've looked at this:
>>         <a href="https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;">https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back
>>         <<a href="https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;">https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back>
>>
>>         And it confuses me. What am I doing wrong???
>>
>>         Btw, I'm not having much luck with '< >', either.
>>         --
>>         You received this message because you are subscribed to the
>>         Google Groups "amber-lang" group.
>>         To unsubscribe from this group and stop receiving emails from
>>         it, send an email to amber-lang+
...@<a href="http://googlegroups.com" target="_blank" rel="nofollow" onmousedown="this.href='http://googlegroups.com';return true;" onclick="this.href='http://googlegroups.com';return true;">googlegroups.com

>>         <javascript:>.
>>         For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout
>>         <<a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "amber-lang" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="zvthmNMLte0J" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">amber-lang+...@googlegroups.com
> <mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="zvthmNMLte0J" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">amber-lang+unsubscribe@...>.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: From Smalltalk to JavaScript

Herby Vojčík


Richard Eng wrote:
> Apparently, I'm not coding the ajax call correctly, because onSuccess:
> is not executed, i.e., I don't get an alert popup. When I used
> getJSON:, I did get an alert popup. So why isn't ajax: working?
>
> As for onSuccess:, my question is whether it's associated with jQuery.
> jQuery has a 'success' callback, but it doesn't seem to take a
> parameter (i.e., the json result). onSuccess: does have a json result
> parameter. Ultimately, my question is, how do I obtain the json result
> from the ajax call?

Yes, from this it is clear that you do not understand how to rewrite JS call to ST message send and you just copied getJSON:onSuccess: from the example without understanding it.

You really must understand how it is done, or these questions never end. Try to reread that wiki page until you get it (onSuccess: is totally unimportant. You can write froznicate:, foobar: or whatever else there; see how keyword message for multiple-arg calls are created
 and how other keywords beyond the first are not used at all beyond the fact that it separates second parameter from the first).

>
> On Saturday, 30 May 2015 08:50:59 UTC-4, Herby wrote:
>
>
>
>     Richard Eng wrote:
>     > Okay, I'm trying to follow your suggestions. This works:
>     >
>     > JQuery current getJSON:
>     >
>     'https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@.../Prometheus
>     <https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@.../Prometheus>'
>
>     > onSuccess: [:jsonData | alert value: 'verified is ',(jsonData at:
>     > 'verified')].
>     >
>     > But when I try to convert to using the ajax call:
>     >
>     > JQuery current ajax: #{'type' -> 'GET'.
>     > 'url' ->
>     >
>     'https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@.../Prometheus
>     <https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@.../Prometheus
>'.
>
>     > 'dataType' -> 'json'}
>     > onSuccess: [:jsonData | alert value: 'verified is ',(jsonData at:
>     > 'verified')].
>     >
>     > onSuccess: is never executed. I don't understand to what class
>     > onSuccess: belongs; it doesn't appear to be part of jQuery.
>
>     ???
>     I don't get this sentence and question in it at all.
>
>     >
>     > I've never heard of done:.
>
>     done, fail, always. Look up jQuery.ajax docs page.
>
>     >
>     >
>     > On Saturday, 30 May 2015 00:56:43 UTC-4, Herby wrote:
>     >
>     > As for `window btoa: 'foo'`, it is
>     preferable not to use `window`
>     > to access globals, but instead use them directly as in `btoa
>     > value: 'foo'`.
>     >
>     > As already mentioned, there was wrong assignment in your code (I
>     > would not use assignment at all and write `JQuery current foo:
>     > 'bar'`, but it's just my preference).
>     >
>     > Otherwise, there should be no problems with using JS calls -
>
     > though for simplicity I always used single-arg ajax: #{ 'url' ->

>     > 'baz'. ... } send (and instead of setting callbacks in options,
>     > which is IIRC deprecated, I used done: and friends on the result
>     > of ajax: send).
>     >
>     > Herby
>     >
>     > Dňa 30. mája 2015 4:02:36 CEST používateľ 'Sebastian Heidbrink'
>     > via amber-lang <[hidden email] <javascript:>> napísal:
>     >
>     > Hmmm.....
>     >
>     > I jjust read that getJson is a shorthand and one can't set
>     > additional options...
>     >
>     > Did you already consider to do it this way?
>     > ---------------------------
>     -------
>     > get: aUrlString do: aBlock onError: errorBlock
>     >
>     > jQuery ajax: aUrlString
>     > options: #{
>     > 'type' -> 'GET'.
>     > 'contentType' -> 'application/json'.
>     > 'beforeSend' -> [:xhr | |enc| enc = window btoa: 'usr:pwd'.
>     >
>     > xhr setRequestHeader: 'Authorization' with: 'Basic ',enc]
.

>     >
>     > 'complete' -> [:res |
>     > res status = 200
>     > ifTrue: [aBlock value: res responseText]
>     > ifFalse: [errorBlock value: res responseText]
>     > }
>     > ---------------------------------------
>     >
>     > or something like:
>     >
>     > jQuery = JQuery current.
>     >
>     > jQuery ajaxSetup: #{
>     > 'headers' -> #{
>     > |'Authorization':'Basic faskd52352rwfsdfs'|;
>     > ||}
>     > }.
>     >
>     > jQuery getJSON: 'some-url'
>     >
>     > onSuccess: [:jsonData | "do something with jsonData"].
>     >
>     >
>     >
>     > |Just guessing the seperators, I still struggle with the right
>     > Array {} s
>     yntax.
>     >
>     > Sebastian
>     > |
>     > On 2015-05-29 4:21 PM, Richard Eng wrote:
>     >> Okay, obviously, I am not grokking this whole JavaScript
>     >> interfacing thing. I've got to find a way to wrap my head
>     >> around it.
>     >>
>     >> According to this webpage:
>     >>
>     http://stac
koverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax

>     <http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax>
>
>     >>
>     <http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax
>     <http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax>>
>
>     >>
>     >> I can use jQuery's /beforeSend/ callback to add a HTTP header
>     >> with authentication information:
>     >>
>     >> beforeSend: function (xhr) {
>     >> xhr.setRequestHeader ("Authorization", "Basic XXXXXX");
>     >> },
>     >>
>     >>
>     >> So in my Amber code, I tried this:
>     >>
>     >> jQuery = JQuery current.
>     >> jQuery getJSON: 'some-url'
>     >>
>     >> beforeSend: [:xhr | |enc| enc = window btoa: 'usr:pwd'.
>     >>
>     >> xhr setRequestHead
>     er: 'Authorization' put: 'Basic ',enc]
>     >>
>     >> onSuccess: [:jsonData | "do something with jsonData"].
>     >>

>     >>
>     >> It does not understand btoa:, even though the following works
>     >> perfectly in the Workspace:
>     >>
>     >> window btoa: 'usr:pwd'
>     >>
>     >>
>     >> When I get rid of the btoa stuff, it complains that it does
>     >> not understand setRequestHeader:.
>     >>
>     >> I've looked at this:
>     >>
>     https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back
>     <https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back>
>
>     >>
>     <https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back
>     <https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back>>
>
>     >>
>     >> And it confuses me. What am I doing wrong???
>     >>
>     >> Btw, I'm not having much luck with '< >', either.
>     >> --
>     >> You received this message because you are subscribed to the
>     >> Google Groups "amber-lang" group.
>     >> To unsubsc
ribe from this group and stop receiving emails from

>     >> it, send an email to amber-lang+
>     ...@googlegroups.com <http://googlegroups.com>
>     >> <javascript:>.
>     >> For more options, visit https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>
>     >> <https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>>.
>     >
>     > --
>     > You received this message because you are subscribed to the Google
>     > Groups "amber-lang" group.
>     > To unsubscribe from this group and stop receiving emails from
>     it, send
>     > an email to [hidden email] <javascript:>
>     > <mailto:[hidden email] <javascript:>>.
>     > For more options, visit https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "amber-lang" group.
> To unsubscribe from this group and stop receiv
ing emails from it, send
> an email to [hidden email]
> <mailto:[hidden email]>.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: From Smalltalk to JavaScript

horrido
I finally got a handle on it. It turns out that all my problems were related to CORS (http://stackoverflow.com/questions/21850454/how-to-make-xmlhttprequest-cross-domain-withcredentials-http-authorization-cor). To bypass all this CORS shit, I decided to do my own user authorization. Works like a charm.


On Saturday, 30 May 2015 09:38:06 UTC-4, Herby wrote:


Richard Eng wrote:
> Apparently, I'm not coding the ajax call correctly, because onSuccess:
> is not executed, i.e., I don't get an alert popup. When I used
> getJSON:, I did get an alert popup. So why isn't ajax: working?
>
> As for onSuccess:, my question is whether it's associated with jQuery.
> jQuery has a 'success' callback, but it doesn't seem to take a
> parameter (i.e., the json result). onSuccess: does have a json result
> parameter. Ultimately, my question is, how do I obtain the json result
> from the ajax call?

Yes, from this it is clear that you do not understand how to rewrite JS call to ST message send and you just copied getJSON:onSuccess: from the example without understanding it.

You really must understand how it is done, or these questions never end. Try to reread that wiki page until you get it (onSuccess: is totally unimportant. You can write froznicate:, foobar: or whatever else there; see how keyword message for multiple-arg calls are created
 and how other keywords beyond the first are not used at all beyond the fact that it separates second parameter from the first).

>
> On Saturday, 30 May 2015 08:50:59 UTC-4, Herby wrote:
>
>
>
>     Richard Eng wrote:
>     > Okay, I'm trying to follow your suggestions. This works:
>     >
>     > JQuery current getJSON:
>     >
>     '<a href="https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@gmail.com/Prometheus" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmiramar21.com%2Ftut_server%2Fdefault%2Fapi%2Fverify%2Fperson%2Fhorrido.hobbies%40gmail.com%2FPrometheus\46sa\75D\46sntz\0751\46usg\75AFQjCNEF8Z2VKQJtTEMMKk3Ac3jVPyqkUQ';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmiramar21.com%2Ftut_server%2Fdefault%2Fapi%2Fverify%2Fperson%2Fhorrido.hobbies%40gmail.com%2FPrometheus\46sa\75D\46sntz\0751\46usg\75AFQjCNEF8Z2VKQJtTEMMKk3Ac3jVPyqkUQ';return true;">https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@gmail.com/Prometheus
>     <<a href="https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@gmail.com/Prometheus" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmiramar21.com%2Ftut_server%2Fdefault%2Fapi%2Fverify%2Fperson%2Fhorrido.hobbies%40gmail.com%2FPrometheus\46sa\75D\46sntz\0751\46usg\75AFQjCNEF8Z2VKQJtTEMMKk3Ac3jVPyqkUQ';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmiramar21.com%2Ftut_server%2Fdefault%2Fapi%2Fverify%2Fperson%2Fhorrido.hobbies%40gmail.com%2FPrometheus\46sa\75D\46sntz\0751\46usg\75AFQjCNEF8Z2VKQJtTEMMKk3Ac3jVPyqkUQ';return true;">https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@gmail.com/Prometheus>'
>
>     > onSuccess: [:jsonData | alert value: 'verified is ',(jsonData at:
>     > 'verified')].
>     >
>     > But when I try to convert to using the ajax call:
>     >
>     > JQuery current ajax: #{'type' -> 'GET'.
>     > 'url' ->
>     >
>     '<a href="https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@gmail.com/Prometheus" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmiramar21.com%2Ftut_server%2Fdefault%2Fapi%2Fverify%2Fperson%2Fhorrido.hobbies%40gmail.com%2FPrometheus\46sa\75D\46sntz\0751\46usg\75AFQjCNEF8Z2VKQJtTEMMKk3Ac3jVPyqkUQ';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmiramar21.com%2Ftut_server%2Fdefault%2Fapi%2Fverify%2Fperson%2Fhorrido.hobbies%40gmail.com%2FPrometheus\46sa\75D\46sntz\0751\46usg\75AFQjCNEF8Z2VKQJtTEMMKk3Ac3jVPyqkUQ';return true;">https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@gmail.com/Prometheus
>     <<a href="https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@gmail.com/Prometheus" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmiramar21.com%2Ftut_server%2Fdefault%2Fapi%2Fverify%2Fperson%2Fhorrido.hobbies%40gmail.com%2FPrometheus\46sa\75D\46sntz\0751\46usg\75AFQjCNEF8Z2VKQJtTEMMKk3Ac3jVPyqkUQ';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmiramar21.com%2Ftut_server%2Fdefault%2Fapi%2Fverify%2Fperson%2Fhorrido.hobbies%40gmail.com%2FPrometheus\46sa\75D\46sntz\0751\46usg\75AFQjCNEF8Z2VKQJtTEMMKk3Ac3jVPyqkUQ';return true;">https://miramar21.com/tut_server/default/api/verify/person/horrido.hobbies@gmail.com/Prometheus
>'.
>
>     > 'dataType' -> 'json'}
>     > onSuccess: [:jsonData | alert value: 'verified is ',(jsonData at:
>     > 'verified')].
>     >
>     > onSuccess: is never executed. I don't understand to what class
>     > onSuccess: belongs; it doesn't appear to be part of jQuery.
>
>     ???
>     I don't get this sentence and question in it at all.
>
>     >
>     > I've never heard of done:.
>
>     done, fail, always. Look up jQuery.ajax docs page.
>
>     >
>     >
>     > On Saturday, 30 May 2015 00:56:43 UTC-4, Herby wrote:
>     >
>     > As for `window btoa: 'foo'`, it is
>     preferable not to use `window`
>     > to access globals, but instead use them directly as in `btoa
>     > value: 'foo'`.
>     >
>     > As already mentioned, there was wrong assignment in your code (I
>     > would not use assignment at all and write `JQuery current foo:
>     > 'bar'`, but it's just my preference).
>     >
>     > Otherwise, there should be no problems with using JS calls -
>
     > though for simplicity I always used single-arg ajax: #{ 'url' ->

>     > 'baz'. ... } send (and instead of setting callbacks in options,
>     > which is IIRC deprecated, I used done: and friends on the result
>     > of ajax: send).
>     >
>     > Herby
>     >
>     > Dňa 30. mája 2015 4:02:36 CEST používateľ 'Sebastian Heidbrink'
>     > via amber-lang <[hidden email] <javascript:>> napísal:
>     >
>     > Hmmm.....
>     >
>     > I jjust read that getJson is a shorthand and one can't set
>     > additional options...
>     >
>     > Did you already consider to do it this way?
>     > ---------------------------
>     -------
>     > get: aUrlString do: aBlock onError: errorBlock
>     >
>     > jQuery ajax: aUrlString
>     > options: #{
>     > 'type' -> 'GET'.
>     > 'contentType' -> 'application/json'.
>     > 'beforeSend' -> [:xhr | |enc| enc = window btoa: 'usr:pwd'.
>     >
>     > xhr setRequestHeader: 'Authorization' with: 'Basic ',enc]
.

>     >
>     > 'complete' -> [:res |
>     > res status = 200
>     > ifTrue: [aBlock value: res responseText]
>     > ifFalse: [errorBlock value: res responseText]
>     > }
>     > ---------------------------------------
>     >
>     > or something like:
>     >
>     > jQuery = JQuery current.
>     >
>     > jQuery ajaxSetup: #{
>     > 'headers' -> #{
>     > |'Authorization':'Basic faskd52352rwfsdfs'|;
>     > ||}
>     > }.
>     >
>     > jQuery getJSON: 'some-url'
>     >
>     > onSuccess: [:jsonData | "do something with jsonData"].
>     >
>     >
>     >
>     > |Just guessing the seperators, I still struggle with the right
>     > Array {} s
>     yntax.
>     >
>     > Sebastian
>     > |
>     > On 2015-05-29 4:21 PM, Richard Eng wrote:
>     >> Okay, obviously, I am not grokking this whole JavaScript
>     >> interfacing thing. I've got to find a way to wrap my head
>     >> around it.
>     >>
>     >> According to this webpage:
>     >>
>     <a href="http://stac" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstac\46sa\75D\46sntz\0751\46usg\75AFQjCNE4cdxPc4j6tLSzLb7DAss_tyanCQ';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstac\46sa\75D\46sntz\0751\46usg\75AFQjCNE4cdxPc4j6tLSzLb7DAss_tyanCQ';return true;">http://stac
<a href="http://koverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fkoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNGpMtxGQopO4Qn_cGzTDkSraaaN0g';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fkoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNGpMtxGQopO4Qn_cGzTDkSraaaN0g';return true;">koverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax

>     <<a href="http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;">http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax>
>
>     >>
>     <<a href="http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;">http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax
>     <<a href="http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5507234%2Fhow-to-use-basic-auth-and-jquery-and-ajax\46sa\75D\46sntz\0751\46usg\75AFQjCNHLVwoaLZbWKF25gNMniRNJZT5lTA';return true;">http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax>>
>
>     >>
>     >> I can use jQuery's /beforeSend/ callback to add a HTTP header
>     >> with authentication information:
>     >>
>     >> beforeSend: function (xhr) {
>     >> xhr.setRequestHeader ("Authorization", "Basic XXXXXX");
>     >> },
>     >>
>     >>
>     >> So in my Amber code, I tried this:
>     >>
>     >> jQuery = JQuery current.
>     >> jQuery getJSON: 'some-url'
>     >>
>     >> beforeSend: [:xhr | |enc| enc = window btoa: 'usr:pwd'.
>     >>
>     >> xhr setRequestHead
>     er: 'Authorization' put: 'Basic ',enc]
>     >>
>     >> onSuccess: [:jsonData | "do something with jsonData"].
>     >>

>     >>
>     >> It does not understand btoa:, even though the following works
>     >> perfectly in the Workspace:
>     >>
>     >> window btoa: 'usr:pwd'
>     >>
>     >>
>     >> When I get rid of the btoa stuff, it complains that it does
>     >> not understand setRequestHeader:.
>     >>
>     >> I've looked at this:
>     >>
>     <a href="https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;">https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back
>     <<a href="https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;">https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back>
>
>     >>
>     <<a href="https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;">https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back
>     <<a href="https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Famber-smalltalk%2Famber%2Fwiki%2FFrom-smalltalk-to-javascript-and-back\46sa\75D\46sntz\0751\46usg\75AFQjCNFEoAvzKjJ20Ozb5129ypzW2j5ZSw';return true;">https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back>>
>
>     >>
>     >> And it confuses me. What am I doing wrong???
>     >>
>     >> Btw, I'm not having much luck with '< >', either.
>     >> --
>     >> You received this message because you are subscribed to the
>     >> Google Groups "amber-lang" group.
>     >> To unsubsc
ribe from this group and stop receiving emails from

>     >> it, send an email to amber-lang+
>     ...@<a href="http://googlegroups.com" target="_blank" rel="nofollow" onmousedown="this.href='http://googlegroups.com';return true;" onclick="this.href='http://googlegroups.com';return true;">googlegroups.com <<a href="http://googlegroups.com" target="_blank" rel="nofollow" onmousedown="this.href='http://googlegroups.com';return true;" onclick="this.href='http://googlegroups.com';return true;">http://googlegroups.com>
>     >> <javascript:>.
>     >> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout
>     <<a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout>
>     >> <<a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout
>     <<a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout>>.
>     >
>     > --
>     > You received this message because you are subscribed to the Google
>     > Groups "amber-lang" group.
>     > To unsubscribe from this group and stop receiving emails from
>     it, send
>     > an email to amber-lang+...@googlegroups.com <javascript:>
>     > <mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="K0jmw_HpeAwJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">amber-lang+unsubscribe@... <javascript:>>.
>     > For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout
>     <<a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "amber-lang" group.
> To unsubscribe from this group and stop receiv
ing emails from it, send
> an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="K0jmw_HpeAwJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">amber-lang+...@googlegroups.com
> <mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="K0jmw_HpeAwJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">amber-lang+unsubscribe@...>.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: From Smalltalk to JavaScript

Herby Vojčík


Richard Eng wrote:
> I finally got a handle on it. It turns out that all my problems were
> related to CORS

I am pretty sure that's not the case.

> (http://stackoverflow.com/questions/21850454/how-to-make-xmlhttprequest-cross-domain-withcredentials-http-authorization-cor).
> To bypass all this CORS shit, I decided to do my own user

You cannot 'bypass' CORS (in fact, SOP) by any means.

> authorization. Works like a charm.

Though I am not going to argue - let it work until it works.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: From Smalltalk to JavaScript

horrido
I didn't mean bypass CORS itself, just bypass the complexity of dealing with preflighted requests and OPTIONS headers. I had to accommodate CORS in the REST api server, so I didn't actually bypass it.

To apply user authorization for accessing the REST api, it's simply a matter of POSTing the credentials via SSL and doing the checking in the server-side code. AFAIK, this is perfectly secure.


On Sunday, 31 May 2015 11:09:56 UTC-4, Herby wrote:


Richard Eng wrote:
> I finally got a handle on it. It turns out that all my problems were
> related to CORS

I am pretty sure that's not the case.

> (<a href="http://stackoverflow.com/questions/21850454/how-to-make-xmlhttprequest-cross-domain-withcredentials-http-authorization-cor" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F21850454%2Fhow-to-make-xmlhttprequest-cross-domain-withcredentials-http-authorization-cor\46sa\75D\46sntz\0751\46usg\75AFQjCNFStvvRLMVrq0_nXJwE6uBbCsiPGg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F21850454%2Fhow-to-make-xmlhttprequest-cross-domain-withcredentials-http-authorization-cor\46sa\75D\46sntz\0751\46usg\75AFQjCNFStvvRLMVrq0_nXJwE6uBbCsiPGg';return true;">http://stackoverflow.com/questions/21850454/how-to-make-xmlhttprequest-cross-domain-withcredentials-http-authorization-cor).
> To bypass all this CORS shit, I decided to do my own user

You cannot 'bypass' CORS (in fact, SOP) by any means.

> authorization. Works like a charm.

Though I am not going to argue - let it work until it works.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.