Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //code about that gets the user's answers from a form
- //then the code below
- function ajax1() {//put in database
- $.ajax({
- url: "php/newComment.php",
- method: "POST",
- data: ({'artwork': artwork, 'ip': ip, 'timestamp': timestamp, 'rank': rank, 'comment': comment}),
- success: function(data) {
- },
- error: function(jxhr, statusText, err) {
- }
- });
- } //all good here; it works
- $.when(ajax1()).done(function(){
- $.ajax({ //fetch the number of responses
- //and average data from dB
- url: "php/get-averages-number.php",
- method: "POST",
- data: ({'artwork': artwork}),
- success: function(data) {
- var objArt = jQuery.parseJSON( data );
- for (i=0; i<objArt.length; i++) {
- if (artwork == objArt[i].artwork) {
- $('#' + artwork + '-respondents').text(objArt[i].num + " respondent(s) so far");
- var score = parseFloat(objArt[i].avg);
- var rounded = Math.round( score * 10 ) / 10;
- $('#' + artwork + '-average').text(rounded.toFixed(1) + " average score");
- }
- }
- },
- error: function(jxhr, statusText, err) {
- }
- }); //this works, but doesn't always reflect that
- //a new response was just entered
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement