title: Cross Origin Resource Sharing with PrototypeJS
body: <p>I am facing a common issue CORS with Prototype Ajax request.  I Googled for about 2 hours, and still I am not able to fix the issue. I tried a different approach. Nothing helped me. I need to set orgin, <code>Access-Control-Allow-Origin</code>, etc. in my code. I referred to the following sites, but they were of no help.</p>
  
  <p><a href="http://kourge.net/node/131" rel="nofollow noreferrer">http://kourge.net/node/131</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3413762/cross-origin-resource-sharing-with-prototypejs">Cross Origin Resource Sharing with PrototypeJS</a></p>
  
  <pre><code>new Ajax.Request("http://localhost:4000/somefolder/some.xml", {
      //new Ajax.Request(source, {
          asynchronous: false,
          method: 'get',
          contentType: 'text/xml',
          //requestHeaders: ('Access-Control-Allow-Origin', '*','Access-Control-Allow-Methods','GET','Access-Control-Max-Age','1000','Access-Control-Allow-Headers','*' ),
          //requestHeaders: (Access-Control-Allow-Origin, *,Access-Control-Allow-Methods,GET,Access-Control-Max-Age,1000,Access-Control-Allow-Headers,*),
          //onCreate: function(request) { 
          //   request.transport.setRequestHeader = Prototype.emptyFunction; 
      // },
      requestHeaders: {Access: '*/*'},
      onSuccess: function(result) {   
          alert(result.responseXML);
      }
  }); 
  </code></pre>
  
  <p>And I'm getting the following response:</p>
  
  <pre><code>Response Headersview source
  Connection  keep-alive
  Content-Length  0
  Content-Type    text/html; charset=utf-8
  Date    Thu, 05 Jul 2012 08:58:08 GMT
  X-Powered-By    Express
  Request Headersview source
  Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Encoding gzip, deflate
  Accept-Language en-us,en;q=0.5
  Access-Control-Request-He...    x-prototype-version,x-requested-with
  Access-Control-Request-Me...    GET
  Connection  keep-alive
  Host    localhost:4000
  Origin  http://localhost:8080
  User-Agent  Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0
  </code></pre>
  
  <p>I am sending it as a <code>GET</code> request, but it's going as an <code>OPTIONS</code> request.</p>
  
  <hr>
  
  <p>I added the header in response also. Still no help.</p>
  
  <pre><code>app.configure('development', function() {
      app.use(express.errorHandler( {
          dumpExceptions :true,
          showStack :true
      }));
      app.all('*', function(req, res, next) { 
          res.setHeader('Access-Control-Allow-Origin', 'http://localhost:4000, http://localhost:8000');
          res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE');
          res.setHeader('Access-Control-Allow-Headers', 'x-prototype-version,x-requested-with');
          res.setHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
          res.setHeader('Accept-Encoding', 'gzip, deflate');
          res.setHeader('Accept-Language', 'en-us,en;q=0.5');
          res.setHeader("X-Requested-With", "XMLHttpRequest" );
          res.setHeader("Orgin", 'http://localhost:4000'); 
          next()
      });
  });
  </code></pre>
  
  <p>The added/reflected response:</p>
  
  <pre><code>Response Headersview source
  
  Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Encoding gzip, deflate
  Accept-Language en-us,en;q=0.5
  Access-Control-Allow-Head...    x-prototype-version,x-requested-with
  Access-Control-Allow-Meth...    GET,POST,PUT,DELETE
  Access-Control-Allow-Orig...    http://localhost:4000, http://localhost:8000
  Allow   GET,POST,PUT,DELETE,TRACE,CONNECT,PROPFIND,PROPPATCH,MKCOL,COPY,MOVE,LOCK,UNLOCK,VERSION-CONTROL,REPORT,CHECKOUT,CHECKIN,UNCHECKOUT,MKWORKSPACE,UPDATE,LABEL,MERGE,BASELINE-CONTROL,MKACTIVITY,ORDERPATCH,ACL,SEARCH,PATCH,PURGE
  Connection  keep-alive
  Content-Length  224
  Content-Type    text/html; charset=utf-8
  Date    Fri, 06 Jul 2012 06:20:51 GMT
  Orgin   http://localhost:4000
  X-Powered-By    Express
  X-Requested-With    XMLHttpRequest
  
  Request Headersview source
  
  Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Encoding gzip, deflate
  Accept-Language en-us,en;q=0.5
  Access-Control-Request-He...    x-prototype-version,x-requested-with
  Access-Control-Request-Me...    GET
  Connection  keep-alive
  Host    localhost:4000
  Origin  http://localhost:8080
  User-Agent  Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0
  </code></pre>
  
  <p>What else can I do to fix this issue?</p>