![]() |
How to update comment count?
How would I update the count or comment count after doing an insert?
I have a working system but can't ever update the comment count without refreshing the entire page. Is there a trick in getting the data from the db? Edit: One other method is to add an extra column, updating the count each time a comment gets added, this would mean that I need to add my own auto-inc. values. |
Just out of curiosity this can't be done without a page refresh?
Update a div after posting your comment? If this is the case, I see no point in bothering with AJAX when I can do it the normal way. |
wait... what now?
of course you can update a div with the return from an ajax request... |
Quote:
Edit: Code added; PHP Code:
Cheers |
Ya, your code would be nice.
In specific, the ajax request handler function and the div you want updated. EDIT: Just realized you might not have created any ajax yet, in which case you need to tell us what server-side script you have available for communicating with your database (hoping for ASP or PHP with MySQL). |
Just added it above.
Edit: PHP with MySQL Here is ajax.php below; PHP Code:
$('div.success').fadeIn(); I've added to reload the page window.location.reload()Forgot to add the comment count method. Sorry! PHP Code:
|
Quote:
|
I honestly don't have any experience with jQuery (I build all my frameworks myself). But judging from the code you posted, you should be able to do something like this:
Code:
function updateCount()Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
I get Comment added (undefined)
Edit: This is based on ID so get_count.php should be get_count.php?id='$_GET[id]'I really don't think it's possible to update the comment count after the insert. I am open to suggestions, if jQuery can't do it what can? Cheers |
Quote:
Quote:
|
When I add the ?id=id (used 1 and added a couple of 1's) it gave me undefined.
I know there is a method to do this without a page refresh. It just needs requery the database or call the db value. |
All you need is a function that sends an ajax request to a server-side intermediary which in turn requests the data from your database. The JS handler for your request will then update your html count.
It's as simple as that. If you insist on using jQuery, I'm done helping you (already gave you a concept function for jQuery - you're undefined response could be for a number of reasons). If you want to build your own xmlhttprequest object and handlers, go for it and I can help you debug any problems you run into, it's really rather simple. |
All new to jQuery, Ajax and JS, found a method to add a comment without a page refresh.
Yes it's jQuery, but aren't they all? I don't insist on using anything, I am happy to go with what ever works. You said that jQuery can do it. I have a few ebooks;
itsallkizza, I do appreciate your help, Thank you! |
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
Thanks but nothing gets displayed, blank page.
What needs to call the get_count.php? Edit: Have to add updateCount(); at the end after last "}" to display the data. Only issue is that it's not dynamic. In the sense that the id is in the URL with GET[id] |
| All times are GMT +1. The time now is 10:30 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.