Hi I trying to get a page to refresh without using reload. Im using a widget called raty and I need to refresh the page everytime someone rate an image. How can I make it refresh so the current votes and average shows in the divs? Here is the rating jquery plugin code //Raty plugin $(function() { //Below is a path to img folder. $.fn.raty.defaults.path = 'js/img'; //Below will activate Raty on div where class is star. $('.star').raty({ half : true, number: 5, score : 0, click: function(score, evt) { //Below will get id value and store in variable pid var pid=$(this).prop('id'); //Below will post score and id value to raty1.php page behind the scenes. $.post('raty1.php',{score:score, pid:pid}, function(data){ }); } }); }); Code (markup): the votes and average numbers shows in these divs <div class="votes"><?php echo "Antal röster: " . count($names).'<br>';?></div> <div class="average"><?php echo "Genomsnitt: " . $formatted;?></div> Code (markup):
Just update the divs with content received from the ajax (post) function. Calculate the average and any other numbers you need, and send it back from the PHP-file. No need to update the page, just replace the content in the divs
I need to use ajax to refresh. Its for a course Im taking and we need to use ajax to refresh a page. And I dont know how to code that, I google it but found nothing that I understood.
The whole point of AJAX is to obtain _parts of the code_ not the whole page. Ie, you reload parts of the content, or specific items in the code - hence why I said just load the content into the divs in question. Something like this: $.post('raty1.php',{score:score, pid:pid}, function(data){ var data = $.parseJSON(data); //assumes that you return data as JSON $('.average').html(data.average); //assumes that one of the return values is named 'average' and contains the new average number }); Code (markup):