title: Origin http://localhost is not allowed by Access-Control-Allow-Origin.
body: <p>I'm developing a REST webservice in Node.JS to work with the backbone framework.
  I've defined a Person model with urlRoot: <code>http://localhost:3000/users</code> and I've created a request handler which adds the person to a database on receiving a post request. </p>
  
  <p><code>app.post('/users', user.add(db));</code></p>
  
  <pre><code>exports.add = function(db){
      return function(req,res){
  
          console.log(req.body);
  
          var name = req.body.name;
          var age = req.body.age;
          var sex = req.body.sex;
          var job = req.body.job;
  
          var peopleDb = db.get('people');
  
          peopleDb.insert({
              'name':name,
              'age':age,
              'sex':sex,
              'job':job
          },function(e,docs){
              if(e){
                  console.log(e);
              }else
              {
                  res.setHeader('Content-Type','application/json');
                  res.setHeader('Access-Control-Allow-Origin','*');
                  res.setHeader('Access-Control-Allow-Methods','GET,PUT,POST,DELETE');
                  res.writeHead(200);
                  res.end(JSON.stringify(docs));
              }
          });
      }
  }
  </code></pre>
  
  <p>When I try to execute the code, I get this in the console:</p>
  
  <p><code>Origin http://localhost is not allowed by Access-Control-Allow-Origin.</code></p>
  
  <p>I read from other answers that adding the headers:<code>Access-Control-Allow-Origin:*</code> and <code>Access-Control-Allow-Methods:GET,PUT,POST,DELETE</code> would solve the problem but it hasn't worked for me. I have also tried putting these headers in an .htaccess file but no luck.</p>
  
  <p>Can someone tell me if there's something wrong with the code or any solution to this problem?</p>