Als ik via ajax in een node.js server een php bestand in een andere map wil halen krijg ik deze error:
XMLHttpRequest cannot load
http://localhost/ajax/roomInfo.php. No Access-Control-Allow-Origin header is present on the requested resource. Origin http://localhost:8080 is therefore not allowed access.
var express = require(express)
, app = express()
, http = require(http)
, server = http.createServer(app)
, io = require(socket.io).listen(server);
server.listen(8080);
// routing
app.all(/*, function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
//...
app.configure(function() {
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + /));
});
Ajax:
$.ajax({
url: "http://localhost/ajax/roomInfo.php",
type: "POST",
data: { id: 8 },
cache: false,
success: function (response) {
alert("response");
}
});