kkumar
kkumar

Reputation: 355

ajax content loaded by dojo not getting parsed

I loaded ajax content into a div using following code.

function refreshMain(paneUrl){
require(["dojo/_base/xhr", "dojo/on", "dojo/dom", "dojo/parser", "dojo/domReady!"],
        function(xhr, on, dom) {
                xhr.get({
                    url: paneUrl,
                    load: function(newContent) {
                        dom.byId("bottom_div").innerHTML = newContent;
                        dojo.parser.parse();
                    }
                });

        });}

The below script is not working when #show_button is clicked on ajax loaded content. But it works if #show_button is on same page.

require(["dojo/query", "dojo/NodeList-fx", "dojo/NodeList-traverse"], function(query){
query("#show_button").on("click", function(e){
    alert(e.target);
}); });

Upvotes: 0

Views: 432

Answers (2)

sanalks
sanalks

Reputation: 21

For Dojo 1.8+ one can use EventDeligation or Publish/Subscribe techniques to handle events generated from content loaded through ajax or content that will be loaded in the future.

Event Deligate example

<div id="parent">
    <button id="button1" class="btnclass">Click me</button>
</div>

require(["dojo/on", "dojo/dom", "dojo/query", "dojo/domReady!"],
    function(on, dom){
       var btnlick = function(evt){
            alert("Hey Hoo");
        };
        var divp = dom.byId("parent");
        on(divp, ".btnclass:click", btnlick);
});

please refer to the below link for more information.

http://dojotoolkit.org/documentation/tutorials/1.8/events/

Upvotes: 2

kkumar
kkumar

Reputation: 355

it worked when I added the script in load callback function of xhr.get().

Upvotes: 0

Related Questions