0

I am getting the error:

XMLHttpRequest cannot load http://localhost:3000/data. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

The client side and server side code are both pretty simple:

Server:

var express = require('express');
var app = express();

app.get('/data', function(req, res){
  res.send('hello world');
});

app.listen(3000);

Client:

  $(document).ready(function() {
    $.get('http://localhost:3000/data', {}, function(data){
      $("#demo").html(data);
    });
  });

I understand this is a very general issue so I searched for the existing question and answers but none of them quite worked for me as far as I have tried. And both Chrome and FF have the same issue. Any suggestions?

Lance Shi
  • 1,127
  • 3
  • 13
  • 28
  • https://github.com/expressjs/cors – Phil May 06 '16 at 01:47
  • What is the complete url of file that contains the javascript code? – Kashif May 06 '16 at 01:48
  • 1
    I'm guessing you are loading the web page into the browser from the file system which the system calls a `null` origin. Make sure and load it from a `http://localhost:3000/somepath` URL. – jfriend00 May 06 '16 at 02:39

0 Answers0