title: ajax getting response from server
body: <p>I am having trouble getting the response from my server (which is supposed to give me the average of some numbers.</p>
  
  <p>Code for server: </p>
  
  <pre><code>var path = require('path');
  const FileDirectory = "./";
  var sum = 0;
  var count = 0;
  
  http.createServer(function(req, res) {
      console.log('request starting:'+req.method+" "+req.url);
      var dirName = path.dirname(req.url).toLowerCase();
      var baseName = path.basename(req.url).toLowerCase();
      var extName = path.extname(req.url).toLowerCase();
  
  
      // handling "GET /grade" requests
      if (req.method.toLowerCase() === 'get' &amp;&amp; req.url.toLowerCase()==='/grade') {
          if (count&gt;0) {
              currentAverage = sum/count;
          }
          else {
              currentAverage = "NaN";
          }
      }
  
      // handling "POST /grade/1..5" requests
      if (req.method.toLowerCase() === 'post' &amp;&amp; dirName === '/grade') {
  
          sum = sum + parseInt(baseName);
          count++;
          currentAverage = sum/count;
          console.log("Sum:"+sum + " Count:" + count + " Average:" + currentAverage);
      }
  
      if (!!currentAverage) {
          res.writeHead(200, { 'Content-Type': 'text/html' } );
          res.end(""+currentAverage,'utf-8');
          return;
      }
  
      res.writeHead(404);
      res.end();
  }).listen(8888);
  </code></pre>
  
  <p>Now, my client side code: </p>
  
  <pre><code>(...)
  var xhttp;
                xhttp=new XMLHttpRequest();
                xhttp.onreadystatechange = function() {
                  if (xhttp.readyState == 4 &amp;&amp; xhttp.status == 200) {
                    cfunc(xhttp);
                  }
                };
                xhttp.open("POST", 'http://localhost:8888/grade/'+someGrade;
                xhttp.send();
                console.log(xhttp);
                }
  </code></pre>
  
  <p>$('.resultAverage').text(xhttp.responseText);</p>
  
  <p>Can any1 tell me what's wrong here? </p>