Seaside
Seaside copied to clipboard
Ajax code is not generated after javascript function call
I have a button with an Ajax call and the call of a javascript function. Depending on the order of the statements, it works or it does not work.
For reproduction I rendered two buttons
html div
onClick:
(html jQuery ajax script: [ :script | #script inspect ])
,
((html javascript alias: 'getS3Data')
apply: {((html jQuery ajax callback: [ :var | #var inspect ]
value: (html javascript alias: 'value')) asFunction: #(value))});
with: 'works'.
html div
onClick:
((html javascript alias: 'getS3Data')
apply: {((html jQuery ajax callback: [ :var | #var inspect ]
value: (html javascript alias: 'value')) asFunction: #(value))}),
(html jQuery ajax script: [ :script | #script inspect ]);
with: 'does not work'.
It does not render the ajax in the 2nd case:
<div onclick="$.ajax({...});getS3Data(function(value){$.ajax({...})})">works</div>
<div onclick="getS3Data(function(value){$.ajax({...})})">does not work</div>
the javascript function does some s3 script and returns the callback value like this:
<script>
function getS3Data(callback) \{
...
callback(content);
...
}
</script>
```
For completeness, screenshot of the rendered result:
![bildschirmfoto 2018-11-28 um 09 10 46](https://user-images.githubusercontent.com/13763544/49140427-9032f200-f2f4-11e8-9a57-575198d40325.png)
Pharo 6.1 Mac
I've had the same problem before. The issue is that JSScript accept statements but does not render them.
From what I see, the problem here is that JSFunction>>,
adds to the statements inside the function instead of concatenating the function definition statement.
Here's a workaround I just had to come up with (from Seaside 2.8):
SUStream new
nextPutAll: 'document.querySelector("selector").classList.remove("class");';
javascript: (aCanvas javascript
alias: 'window';
call: 'setTimeout' arguments: {
(aCanvas updater
"...") asFunction.
5000 };
yourself);
yourself