Skip to content Skip to sidebar Skip to footer

Function Calls For Dynamically Loaded Content

I have a PHP file that serves up some HTML populated from a MySQL database and is loaded into the DOM. This data is loaded via jQuery load() method into the #navContent divide of t

Solution 1:

You need to initialize that click method AFTER the DOM has been appended with your custom markup. This is a perfect example of a case where OOP programming would do wonders.

You also didn't load the click method into the doc-ready...

<script type="text/javascript">
function MyConstructor()
{
    this.ajaxLoader = '';
    this.dns = 'http://www.someURL';
    this.navContent = '/folder/my_list.php';
    this.bodyContent = '/folder/index.php/somestuff #content';

    this.loadPage = function( url, pageName )
    {
        $("#" + pageName).load(url, function(response){
            $('#navHeaderTitle').text($(response).attr('title'));
        });
        this.toggles();
    }

    this.toggles = function()
    {
            var t = this;
        $("#navItem").click(function(e) {
            e.preventDefault();
            var url = 'http://www.google.com';
            var pageName = 'navContent';
            t.loadPage(url, pageName);
        });
    }

    /**************************************
    *Init Doc-Ready/Doc-Load methods
    **************************************/this.initialize = function()
    {
        this.loadPage( this.dns + this.navContent, "navContent");
        this.loadPage( this.dns + this.bodyContent, "bodyContent");
    }
    this.initialize();
}

$( document ).ready( function(){
    var mc = new MyConstructor();

    //now, you can go ahead and re-run any methods from the mc object :)//mc.loadPage( arg, 'ye matey' );
});
</script>

Post a Comment for "Function Calls For Dynamically Loaded Content"