[jQuery] Re: Please Help - While Loop PHP & JSON - Comment List
#commentWrapper is the selector for the following element: The JS I provided will append that element if it isn't already present. I did have to make a single change: $(body).append(''); to: $("body").append(''); 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 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: > > > > > > go > > > > > > It appears the code you provided amends the DIV. Any thoughts would be > great? > > On Apr 28, 5:11 pm, Jake McGraw 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 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: >> >> > > >> > 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"; >> >> > ?>
[jQuery] Re: Please Help - While Loop PHP & JSON - Comment List
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: go It appears the code you provided amends the DIV. Any thoughts would be great? On Apr 28, 5:11 pm, Jake McGraw 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 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: > > > > > 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"; > > > ?>
[jQuery] Re: Please Help - While Loop PHP & JSON - Comment List
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 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: > > > 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"; > > > ?> >