Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. //code about that gets the user's answers from a form
  2. //then the code below
  3.  
  4. function ajax1() {//put in database
  5. $.ajax({
  6. url: "php/newComment.php",
  7. method: "POST",
  8. data: ({'artwork': artwork, 'ip': ip, 'timestamp': timestamp, 'rank': rank, 'comment': comment}),
  9. success: function(data) {
  10. },
  11. error: function(jxhr, statusText, err) {
  12. }
  13. });
  14. } //all good here; it works
  15.  
  16. $.when(ajax1()).done(function(){
  17.  
  18. $.ajax({ //fetch the number of responses
  19. //and average data from dB
  20. url: "php/get-averages-number.php",
  21. method: "POST",
  22. data: ({'artwork': artwork}),
  23. success: function(data) {
  24. var objArt = jQuery.parseJSON( data );
  25. for (i=0; i<objArt.length; i++) {
  26. if (artwork == objArt[i].artwork) {
  27. $('#' + artwork + '-respondents').text(objArt[i].num + " respondent(s) so far");
  28. var score = parseFloat(objArt[i].avg);
  29. var rounded = Math.round( score * 10 ) / 10;
  30. $('#' + artwork + '-average').text(rounded.toFixed(1) + " average score");
  31. }
  32. }
  33. },
  34. error: function(jxhr, statusText, err) {
  35. }
  36. }); //this works, but doesn't always reflect that
  37. //a new response was just entered
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement