Jump to content


Photo

jquery update html


  • Please log in to reply
3 replies to this topic

#1 brown2005

brown2005

    Advanced Member

  • Members
  • PipPipPip
  • 936 posts

Posted 18 January 2013 - 03:00 PM

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].' &nbsp;&nbsp;&nbsp;<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">&nbsp;<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, 18 January 2013 - 03:03 PM.


#2 BagoZonde

BagoZonde

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 18 January 2013 - 03:43 PM

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, 18 January 2013 - 03:45 PM.

A=1-A ...from Basic...
$a=1-$a ...thru PHP...
LDA $01 EOR #1 ...to 6502 ASM :}

Does it mean I'm going low-level?! ;]

#3 brown2005

brown2005

    Advanced Member

  • Members
  • PipPipPip
  • 936 posts

Posted 18 January 2013 - 04:54 PM

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, 18 January 2013 - 04:55 PM.


#4 BagoZonde

BagoZonde

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 18 January 2013 - 05:17 PM

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, 18 January 2013 - 05:21 PM.

A=1-A ...from Basic...
$a=1-$a ...thru PHP...
LDA $01 EOR #1 ...to 6502 ASM :}

Does it mean I'm going low-level?! ;]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com