title: Apache and Nodejs cross domain ajax issue
body: <p>I am working on application in which I have used two servers hosted on same machine, one is apache which will work as basic host for serving php pages and other side nodejs for communication of rest api, whole application build upon backbone/marionette/requirejs/bootstrap.</p>
  
  <p>Coming to the point, my normal pages are load from apache server like,</p>
  
  <pre><code>http://192.168.20.62/project/design.php
  </code></pre>
  
  <p>and I have configured my model like this,</p>
  
  <pre><code>define(['backbone'],function(Backbone){
  'use strict';
  
  return Backbone.Model.extend({
      url:"http://192.168.20.62:9847/page",
      defaults: {
          ...
      }
  });
  
  });
  </code></pre>
  
  <p>when I try to save model I am suffering from problem of ajax cross domain call and I am ended up with error in my save communication, following is the node/express server,</p>
  
  <pre><code>var express = require('/root/node_modules/express');
  
  
  var app = express();
  
  app.configure(function () {
      app.use(express.json());
      app.use(express.urlencoded());
      app.use(function (req, res, next) {
          res.setHeader('Access-Control-Allow-Origin', 'http://192.168.20.62:9847');
          res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
          res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
          res.setHeader('Access-Control-Allow-Credentials', true);
          next();
      });
  
  })
  
  app.post('/page', function(request, response){
  
      console.log(request.body);
      response.send(request.body);
  
  });
  
  app.listen(9847);
  </code></pre>
  
  <p>as you can see I have already written some patch in server code, but still the same, also I have added .htaccess at root level of both at </p>
  
  <pre><code>http://192.168.20.62 
  </code></pre>
  
  <p>and </p>
  
  <pre><code>http://192.168.20.62:9847 
  </code></pre>
  
  <p>with the following code,</p>
  
  <pre><code>Header add Access-Control-Allow-Origin "*"
  Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
  Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
  </code></pre>
  
  <p>but things are not helping in anyways, if I run chrome by disabling web security then thing are working properly.</p>
  
  <p>chrome.exe --disable-web-security</p>
  
  <p>Can you guys please help me to solve this puzzle, thanks in advance.</p>
  
  <p>following is the error message from chrome javascript console</p>
  
  <pre><code>OPTIONS http://192.168.20.62:9847/page Origin http://192.168.20.62 is not allowed by Access-Control-Allow-Origin. jquery-2.0.3.min.js:6
  
  XMLHttpRequest cannot load http://192.168.20.62:9847/page. Origin http://192.168.20.62 is not allowed by Access-Control-Allow-Origin. 
  </code></pre>