title: Localhost refuses connection from Javascript
body: <p>I am making a single web app that takes information from MYSQL database and displays it on screen using AngularJS and NodeJS. I have set up a node.js server that gives out JSON file from a database. It works fine if I connect to it like this: 192.168.1.57:8888 which is my home server ip or remote connecting my server and using localhost:8888. Doing this downloads the JSON file on my computer.</p>
  
  <p>However. If I'm using javascript to get JSON file from the server it gives me this error:</p>
  
  <pre><code>GET http://localhost:8888/ net::ERR_CONNECTION_REFUSED
  </code></pre>
  
  <p>I have tried connecting to the server with both AngularJS and JQuery and they both give the same error. I've also tried 127.0.0.1 and that doesn't work either. What can I do to fix it or can I do this with a better alternative way?</p>
  
  <p>This is the server code in node.js</p>
  
  <pre><code>var http = require("http");
  mysql = require("mysql");
  
  var connection = mysql.createConnection({
  user: "test",
  password: "test",
  database: "test"
  
  });
  
  
  http.createServer(function (request, response) { 
  
  request.on('end', function () { 
  
      connection.query('SELECT * FROM feedback;', function (error, rows, fields) { 
          response.writeHead(200, { 
              'Content-Type': 'x-application/json' 
          }); 
  
          response.end(JSON.stringify(rows)); 
      }); 
  }); 
  
  
  }).listen(8888);
  </code></pre>
  
  <p>this is the client side in angularJS:</p>
  
  <pre><code>(function(){
  var app = angular.module('question', [ ]);
  
  app.controller("ServerController", [ '$http', function($http){
      $http.get("http://localhost:8888").success(function(data,status,headers,config){
          console.log("success");
      }).error(function(data,status,headers,config){
          console.log("error");
      });
  
  } ]);
  }
  )();
  </code></pre>