Skip to content Skip to sidebar Skip to footer

Nodejs Http Request From Angularjs

I'm currently developing a web application using AngularJS on the fronted and NodeJS on the backend with express. I've had trouble requesting my backend API from the fronted howeve

Solution 1:

Make sure that your frontend and backend servers have the same origin (protocol, host and port). If not, then you does not recieve response since you make cross-origin ajax request. In this case you should send special header from your backend to allow it:

Access-Control-Allow-Origin: *

You can add response header with the following code:

res.set('Access-Control-Allow-Origin', '*');

Solution 2:

res.setHeader('Access-Control-Allow-Origin', '*');

Solution 3:

Use res.status(status).json(obj) instead of res.json(status, obj)

Post a Comment for "Nodejs Http Request From Angularjs"