Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Jquery problems using append

    First off here's the code:

    Code:
    function getLastPost(id,reply){
       var isReply = (reply != undefined) ? "&reply="+reply:"&reply=0";
       $.ajax({
          type: "GET",
          url: "./ajaxphp/getPosts.php",
          data: "amount=1&ID="+id+isReply,
          dataType: "html",
          success: function(data){
             if(reply != undefined){
                if(!$("#post-"+id+" > ul").hasClass("postReply")){
                   $("#post-"+id).append("<ul class=\"postReply\"></ul>");
                }
                
                $(data).hide().prependTo("#post-"+id+" > ul.postReply");
             }else{
                if(!$("#postMain").hasClass("postEntry")){
                   $("#postMain").append("<ul class=\"postEntry\"></ul>");
                }
                
                $(data).hide().prependTo("ul.postEntry");
             }
             $("#post-"+id).fadeIn("slow");
             jsReply();
          }   
       });
    }


    So basically what this function is doing is getting an <li> of data and inserting it into a <ul>. However, if that ul isn't there it will append one. The "id" variable gets the id of the post and inserts it into ul.postEntry, however if the post is a reply to another it will create a ul.postReply within the parent post and put the <li> data into that. Everything in the "else" clause of the conditional works fine. It's just this line that will not work


    Code:
    if(!$("#post-"+id+" > ul").hasClass("postReply")){
                   $("#post-"+id).append("<ul class=\"postReply\"></ul>");
                }
    This conditional checks if there is a ul.postReply and if not make one. I checked it with an alert, and the conditional fires off properly however the append part never works which is weird because the other append works fine. What am I doing wrong?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The only thing I can think is your element "#post-"+id doesn't exist..? Or is it appending the <ul> tag somewhere you're not expecting?

  • #3
    New to the CF scene
    Join Date
    Jan 2011
    Location
    USA
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi ,...
    The append method expects a string or DOM node as argument. You are calling it with an object (json). The contents of this object will depend on the data sent by the server. What does the alert print on your screen? Using FireBug you can inspect the properties available to your json object: console.log(json).
    I hope this information will helps a lot,..

    Regards
    Smith

    -----------------------


  •  

    Posting Permissions

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