tags:

views:

316

answers:

3

Hello,

I have a number of ajax calls with content being inserted by dojo.place. I have dojo widgets in the new content so I have to execute dojo.parser.parse() after the content is "placed".

The trouble is I cannot find away of executing this. If I put the code on next line I gets executed too soon. I have had to put it in a setInterval command but that is a rubbish solution.

oncomplete event on dojo.place anyone. Help really appreciated.

A: 

Unfortunately, you need that setTimeout, because the browsers don't render DOM changes synchronously. As explained in Opera blog: Timing and Synchronization in JavaScript:

Here is an example in pseudo-code:

headlineElement.innerHTML = "Please wait...";
performLongRunningCalculation();
headlineElement.innerHTML = "Finished!";

In Internet Explorer and Mozilla, the text "Please wait..." will never be shown to the user, as the changes are rendered only after the whole script has finished. In Opera, on the other hand, the "Please wait..." text is displayed while the calculation is running.

There are few similar questions in SO:

Maine
A: 

If you create a DOM node from your xhrGotten html, say

var d = document.createElement("div");
d.innerHTML = returned_html;

Then you can parse the new div, creating the widgets before using dojo.place to add the new node to the document.

dojo.parser.parse(d);
dojo.place(d, ref_node, "last");
Ed
+2  A: 

dojo.place() is synchronous, so calling the parser right after the place call shouldn't be an issue. It sounds like the problem is that you are calling the parser before your XHR completes.

Bill Keese