I am trying to access an rss feed using an Ajax request on the client broswer.
$.ajax({
type: 'GET',
url: 'http://feeds.bbci.co.uk/news/business/rss.xml?edition=uk',
crossDomain: true,
dataType: 'xml',
success: function(responseData, textStatus, jqXHR) {
console.log(responseData)
},
error: function (responseData, textStatus, errorThrown) {
alert('failed.');
}
});
This is giving me the 'Access-Control-Allow-Origin' error.
I have installed the cors package so it should be enabled on my server, am i missing something?
server.js file
var express = require('express');
var basicAuth = require('express-basic-auth')
var bodyParser = require('body-parser')
var cors = require('cors');
var app = express();
app.use(cors());
app.get('/', function (req, res) {
// res.send('Hello World');
res.sendFile(__dirname + '/views/index.html');
})
var routes = require('./routes');
app.use('/api', routes);
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("App listening at http://%s:%s", host, port)
})
via user2202098
No comments:
Post a Comment