开发者

problem with dynamic loading content with javascript

开发者 https://www.devze.com 2023-02-22 03:04 出处:网络
I\'m working on a website that is dynamically loading content in a DIV. Everything works fine except when the content contains a jquery plugin (f.e. a twitterfeed) the jquery plugin doesn\'t work..any

I'm working on a website that is dynamically loading content in a DIV. Everything works fine except when the content contains a jquery plugin (f.e. a twitterfeed) the jquery plugin doesn't work..anybody knows how to get the plugins to work?

$(function() {

    var newHash      = "",
        $mainContent = $("#main-content"),
        $pageWrap    = $("#page-wrap"),
        baseHeight   = 0,
        $el;


    $("nav").delegate("a", "click", function() {
        window.location.hash = $(this).attr("href");
        return false;
    });

    $(window).bind('hashchange', function(){

        newHash = window.开发者_Python百科location.hash.substring(1);

        if (newHash) {
            $mainContent
                .find("#guts")
                .fadeOut(200, function() {
                    $mainContent.hide().load(newHash + " #guts", function() {
                        $mainContent.fadeIn(200, function() {
                            $pageWrap.animate({
                                height: baseHeight + $mainContent.height() + "px"
                            });
                        });
                        $("nav a").removeClass("current");
                        $("nav a[href="+newHash+"]").addClass("current");
                    });
                });


        };

    });

    $(window).trigger('hashchange');


});


If you use $.load with a selector ($(target).load("url #selector")), jQuery removes all SCRIPT tags from response.

Some solutions that come to my mind are:

  1. changing the back-end to return only the content required by the script
  2. do a $.get request, treat the reponse as plain text, do string manipulation to extract only the parts you need and then convert the result to DOM nodes. To do it right, a HTML parser is needed.
0

精彩评论

暂无评论...
验证码 换一张
取 消