Execute code after an ajax code ended

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

Execute code after an ajax code ended

CyrilFerlicot
Hi,

I use the project Material Design Lite with seaside to create some
components. With it I generate the html with Seaside and a MDL script
replace some part of the page to initialize the components.

My problem is that for some components, I want to update them without
refreshing the page. I found the piece of code to run to initialize the
components but I don't know how to execute it at the right time.

The piece of code is: `componentHandler.upgradeDom();`

I tried:

html jQuery ajax
  callback: [ self doSomething ];
  onSuccess: (html jQuery script:
    [ :s | s << ((html jQuery id: id) load html:
      [ :ajaxHtml | self renderTableContentOn: ajaxHtml ]) ]) , ';
componentHandler.upgradeDom();'

But it seems that the `componentHandler.upgradeDom()` is executed before
the update of the html, so it is useless.

The only way I could find for now is to add a timeout of 100ms but I
really don't like it because the user will see the page update and if
the component take more than 100ms to be rendered it will not work.

Have someone an idea about how to make it work?

I never really did JS before using seaside so maybe the answer is stupid. :)

--
Cyril Ferlicot

http://www.synectique.eu

165 Avenue Bretagne
Lille 59000 France


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

signature.asc (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Execute code after an ajax code ended

CyrilFerlicot
It's always when we send a mail that we find the answer… :)

Thank to a colleague we found a way. If someone is interested, this works:

html jQuery ajax
  callback: [ self doSomething ];
  onSuccess: (html jQuery script: [ :s |
    s << ((html jQuery id: id) load
      html: [ :ajaxHtml | self renderTableContentOn: ajaxHtml ];
      onComplete: 'componentHandler.upgradeDom();')
  ])

On 02/08/2016 10:21, Cyril Ferlicot Delbecque wrote:

> Hi,
>
> I use the project Material Design Lite with seaside to create some
> components. With it I generate the html with Seaside and a MDL script
> replace some part of the page to initialize the components.
>
> My problem is that for some components, I want to update them without
> refreshing the page. I found the piece of code to run to initialize the
> components but I don't know how to execute it at the right time.
>
> The piece of code is: `componentHandler.upgradeDom();`
>
> I tried:
>
> html jQuery ajax
>   callback: [ self doSomething ];
>   onSuccess: (html jQuery script:
>     [ :s | s << ((html jQuery id: id) load html:
>       [ :ajaxHtml | self renderTableContentOn: ajaxHtml ]) ]) , ';
> componentHandler.upgradeDom();'
>
> But it seems that the `componentHandler.upgradeDom()` is executed before
> the update of the html, so it is useless.
>
> The only way I could find for now is to add a timeout of 100ms but I
> really don't like it because the user will see the page update and if
> the component take more than 100ms to be rendered it will not work.
>
> Have someone an idea about how to make it work?
>
> I never really did JS before using seaside so maybe the answer is stupid. :)
>
--
Cyril Ferlicot

http://www.synectique.eu

165 Avenue Bretagne
Lille 59000 France


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

signature.asc (817 bytes) Download Attachment