Jump to content

jquery update html


brown2005

Recommended Posts

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 by brown2005
Link to comment
Share on other sites

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 by BagoZonde
Link to comment
Share on other sites

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 by brown2005
Link to comment
Share on other sites

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 by BagoZonde
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.