1. $(function () {
  2.     xmlhttp = new XMLHttpRequest()
  3.  
  4.     xmlhttp.open("GET", "mysql.php?p=getfullstats", true);
  5.     xmlhttp.send();
  6.  
  7.     xmlhttp.onreadystatechange = function () {
  8.         if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  9.             var jsontext = xmlhttp.responseText;
  10.             var json = JSON.parse(jsontext);
  11.  
  12.  
  13.             if (jsontext == '[]') {
  14.                 return false
  15.             } else {
  16.  
  17.                 var newTr = '';
  18.  
  19.  
  20.                 for (var i = 0; i < json.length; i++) {
  21.                     newTr += (' / ' + json[i].date + ' ' + json[i].price);
  22.  
  23.  
  24.  
  25.                     // parse a date in dd-mm-yyyy
  26.                     function parseDate(input) {
  27.                         var parts = input.match(/(\d+)/g);
  28.                         // new Date(year, month [, date [, hours[, minutes[, seconds[, ms]]]]])
  29.                         return new Date(parts[2], parts[1] - 1, parts[0]); // months are 0-based
  30.                     }
  31.  
  32.  
  33.  
  34.                     // get sum of prices for given month
  35.                     function getSumForMonth(data, month) {
  36.                         var sum = 0;
  37.                         month -= 1; // months are 0-based
  38.                         $.each(data, function (idx, item) {
  39.                             if (parseDate(item.date).getMonth() == month) {
  40.                                 sum += parseFloat(item.price);
  41.                             }
  42.                         });
  43.                         return sum;
  44.                     }
  45.  
  46.  
  47.                     var sum = getSumForMonth(json, 9); // sum for september
  48.                     console.log(sum);
  49.  
  50.                 }
  51.             }
  52.         }
  53.     }
  54.  
  55. });