Results 1 to 3 of 3

Thread: Load content into div and then use script

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    790

    Load content into div and then use script

    I have a div and I'm loading content into it using jQuery:

    Code:
    $(document).ready(function() {
        
          $('#json_comments').load('json_comments_content.php', function() {
      $.getScript("js/comments.js")});
    
    ....
    ....
    ....
    I want to run the code from js/comments.js after the content is loaded into the div.

    The json_comments_content.php page looks like this:

    HTML Code:
    <div class="items general-item-list">
        <div class="item">
            <div class="item-head">
                <div class="item-details">
                    <img class="item-pic" data-field="pic_url" src="">
                    <a href="" class="item-name primary-link" data-field="username"></a>
                    <span class="item-label" data-field="datetime" data-value="" data-pk=""></span>
                </div>
            </div>
            <div class="item-body"><a href="#" id="comment" class="can_possibly_edit" data-type="textarea" data-field="comment" data-pk="" data-value="" data-placement="right" data-original-title="Enter a comment."></a></div>
        </div>
    </div> 
        <a href="#" class="items-load">Load More...</a> 
    
    <script type="text/javascript">     
        
    $(document).ready(function() {
            
        $('.comments_data').loadmore({
            source: 'json_comments.php',
            step: 15,
            userid: '<?php echo $user->data()->id; ?>'
        });
        
        //on load, disabled the comments editable info on page load so it looks better.
        $('#json_comments a').attr("data-disabled", "true");
    
        
        $.fn.editable.defaults.mode = 'inline';
    
            
    });
        
    </script>
    Whats is happening is: the .loadmore plugin will query the database and display more results when Load More... is clicked.

    Once the items load completely, I need to have this script attached:

    Code:
        $('.edit_me').editable({
            emptytext: ".....",
            url: "ajax_xeditable_update.php?table=comments",
        });
    If I place it in either the main page or the loaded page, it never is called. The .edit_me class is selectively added to certain items that are gotten from the database when items are loaded. This is done in the loadmore.js script.

    Using the .getScript method doesn't make it work either.

    Any ideas?

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Load content into div and then use script

    Where did you get the loadmore plugin? Usually this sort of plugin should include an optional callback on completion, which is where you'd want to put your .edit_me snippet (if I'm properly understanding what you're trying to achieve). If there's no such option, you might be able to modify the plugin code yourself, or just switch to another plugin.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    790

    Re: Load content into div and then use script

    Thanks. I'll work on adding a callback function. I modified and made the loadmore plugin myself based on an online tutorial.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width