Jquery tools: invoke initialization of finished document in script loaded by ajax

I have tabs based on jquery tools that work great and on each tab I load pages using ajax. One of the pages has tools from the other side, which requires the following code:

$(function() { $('.scroll-pane').jScrollPane({showArrows: true}); });

I have no doubt where to place this code (on the loaded ajax page). According to the guys from Flowplayer:

"The script tag should be placed under HTML elements that are not inside the document.ready () event, because this event does not fire for pages loaded using AJAX."

Does this mean encapsulating above in tags <script></script>and placing after tag </html>? This is beyond the scope of the entire document, so it does not seem to be correct ...

Help someone ... where should I put my initialization code in an ajax document?

thank

+3
source share
3 answers

Run it as a callback to load AJAX, so the code will run after the HTML has been loaded into the DOM.

$('#result').load('ajax/test.html', function() {
  $(function() { $('.scroll-pane').jScrollPane({showArrows: true}); });
});

More details in the API forload() .

0
source

This is a pretty long shot, but I'm sure you can use the event onClick. I believe this starts after loading the contents of the tab, even through AJAX. You should write something like this:

$("ul.tabs").tabs("div.panes > div", {
    effect: 'ajax',
    onClick: function(event, index) {
        $('.scroll-pane').jScrollPane({showArrows: true});
    }
});

Hope this works for you. If so, it is highly undocumented.

0
source

, .

a) script , script

b)

b :

 function loadScript(sScriptSrc, oCallback) {
    var oHead = document.getElementById('head')[0];
    var oScript = document.createElement('script');
    oScript.type = 'text/javascript';
    oScript.src = sScriptSrc;
    // most browsers
    oScript.onload = oCallback;
    // IE 6 & 7
    oScript.onreadystatechange = function() {
        if (this.readyState == 'complete') {
            oCallback();
        }
    }
    oHead.appendChild(oScript);
}

I need its structural problem, not the script. This means that the WHA / HOW / WHERE and script data are loaded when ajax is called. It will be best if you share a demo link where this happens. I will be happy to help.

Let me know if I understand your problem.

0
source

All Articles