#commentWrapper is the selector for the following element:

<ul id="commentWrapper"></ul>

The JS I provided will append that element if it isn't already
present. I did have to make a single change:

$(body).append('<ul id="commentWrapper"></ul>');

to:

$("body").append('<ul id="commentWrapper"></ul>');

Also, you should specify the type expected for the $.post call:

$.post(url, data, callback, ### type goes here ###);

For your purposes:

$.post("url", {/* data */}, function(data){/* callback */}, "json");

I've updated the following example code:

http://snipt.net/jakemcgraw/jquery-listserv-answer-ajax-comment-list

- jake

On Tue, Apr 28, 2009 at 10:55 PM, fluxUX <martine...@gmail.com> wrote:
>
> This is great. Thanks so much!
>
> For some reason the DIV for the "commentWrapper" is not working on the
> render page..here is what I have:
>
> </head>
>
> <body>
> <input name="u" id="u" type="hidden" value="A_u3V" />
> <a href="#" id='goComment'>go</a>
> <div id="commentWrapper"></div>
>
> </body>
> </html>
>
> It appears the code you provided amends the DIV. Any thoughts would be
> great?
>
> On Apr 28, 5:11 pm, Jake McGraw <jmcgr...@gmail.com> wrote:
>> You've got quite a few errors in both your JavaScript and PHP, which
>> probably explains the lack of answers. Utilizing AJAX using jQuery and
>> PHP can be a bit confusing at first, I've tried to make some sense of
>> what you're doing here:
>>
>> http://snipt.net/jakemcgraw/jquery-listserv-answer-ajax-comment-list
>>
>> - jake
>>
>> On Tue, Apr 28, 2009 at 12:17 PM, fluxUX <martine...@gmail.com> wrote:
>>
>> > I want to display an unordered list of comments from my echoed JSON
>> > result using this jQuery code block:
>>
>> > $("#goComment").click(function(){
>>
>> > bigComment = $("#bigComment").val();
>>
>> >                    $.post("i-upComments.php", {      //this inserts the 
>> > comment
>> > into the 'comments' table in the DB
>>
>> >                bigComment: bigComment,
>> >                u: u,
>>
>> >            }, function(data){
>>
>> >           //display the list of comments as a unordered list - LI
>>
>> >        });
>>
>> >        });
>>
>> > -----------------
>> > Here is my PHP:
>>
>> > <?php
>>
>> > include_once("db.php");
>>
>> > $u = 'Jl6XR';
>>
>> > $sql = "SELECT * FROM bigNest INNER JOIN comments ON comments.u =
>> > bigNest.uid";
>>
>> > $result = mysql_query($sql);
>>
>> > while($array = mysql_fetch_array($result)) {
>>
>> > $bigtitle = $array[bigtitle];
>> > $bigbody = $array[bigbody];
>> > $comments = $array[comments];
>> > }
>>
>> > $val = array("bigtitle" => $bigtitle,
>> >             "bigbody" => $bigbody,
>> >             "comments" => $comments,
>>
>> >            );
>>
>> > $output = json_encode($val);
>> > echo $output."\n";
>>
>> > ?>

Reply via email to