brown2005 Posted January 18, 2013 Share Posted January 18, 2013 (edited) I have the following code, which I have got working with the auto post part, but it is not refreshing the form to allow the items I have posted to the database, but when I refresh the browser they show up. this is my php/html: echo'<ol id="update">'; while($comments_row = mysql_fetch_array($comments_sql)){ echo'<li class="">'.$comments_row[textarea_keywords].' <a href="delete.php?id='.$comments_row[textarea_id].'" title="Remove Keyword">x</a></li>'; } echo'</ol> <div id="flash"></div> <form action="#" method="post"> <textarea rows="7" cols="60" name="comment" id="comment" placeholder="enter your comment here"></textarea> <input type="submit" class="submit" value=" Submit Comment " /> </form> this is my code: $(function() { $(".submit").click(function() { var comment = $("#comment").val(); var dataString = 'comment=' + comment; if(comment==''){ alert('Please Give Valide Details'); }else{ $("#flash").show(); $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" align="absmiddle"> <span class="loading">Loading Comment...</span>'); $.ajax({ type: "POST", url: "commentajax.php", data: dataString, cache: false, success: function(html){ $("ol#update").append(html); $("ol#update li:last").fadeIn("slow"); $("#flash").hide(); } }); } return false; }); }); Edited January 18, 2013 by brown2005 Quote Link to comment https://forums.phpfreaks.com/topic/273339-jquery-update-html/ Share on other sites More sharing options...
BagoZonde Posted January 18, 2013 Share Posted January 18, 2013 (edited) It's because you don't print your record. In html variable you receive response from executed PHP script and your code appending it to ol#update. So let's try to add something like print 'Hello world!'; in commentajax.php then you will see what I'm talking about . Entry should be printed there. Edited January 18, 2013 by BagoZonde Quote Link to comment https://forums.phpfreaks.com/topic/273339-jquery-update-html/#findComment-1406805 Share on other sites More sharing options...
brown2005 Posted January 18, 2013 Author Share Posted January 18, 2013 (edited) It's because you don't print your record. In html variable you receive response from executed PHP script and your code appending it to ol#update. So let's try to add something like print 'Hello world!'; in commentajax.php then you will see what I'm talking about . Entry should be printed there. ok that prints Hello world, but what I want to do is show all the results from the database within the ol tag <ol id="update" class="timeline">'; $comments_sql = mysql_query("SELECT * FROM domains_comments WHERE domains_comments_selmgec='$selmgec' AND domains_comments_domain='$domains_id' ORDER BY domains_comments_date DESC LIMIT 10"); while($comments_row = mysql_fetch_array($comments_sql)){ echo'<li>'.$comments_row[domains_comments_member].'<br />'.$comments_row[domains_comments_date].'<br />'.$comments_row[domains_comments_comment].'</li>'; } echo' </ol> so how would I refresh this, without actually pressing refresh? Edited January 18, 2013 by brown2005 Quote Link to comment https://forums.phpfreaks.com/topic/273339-jquery-update-html/#findComment-1406828 Share on other sites More sharing options...
BagoZonde Posted January 18, 2013 Share Posted January 18, 2013 (edited) It's hard to work without real code as I'm not understanding what do you want, and I'm not sure what inside your commentajax.php at all? If you want to add some line to ol#update, just print parsed values from $_POST which going to database too. And if you want to change all stuff in ol#update, just change jQuery part: $("ol#update").append(html); to: $("ol#update").html(html); Edited January 18, 2013 by BagoZonde Quote Link to comment https://forums.phpfreaks.com/topic/273339-jquery-update-html/#findComment-1406838 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.