Origin http://localhost is not allowed by Access-Control-Allow-Origin

后端 未结 5 885
臣服心动
臣服心动 2020-12-05 20:29

I\'m trying to do a fetch from backbone.js to my node.js server. However, I get the following error in the console:

Origin http://localhost is not allowed by A

5条回答
  •  天涯浪人
    2020-12-05 21:07

    If you are making the fetch call to your localhost which I'm guessing is run by node.js in the same directory as your backbone code, than it will most likely be on http://localhost:3000 or something like that. Than this should be your model:

    var model = Backbone.Model.extend({
        url: '/item'
    });
    

    And in your node.js you now have to accept that call like this:

    app.get('/item', function(req, res){
        res.send('some info here');
    });
    

提交回复
热议问题