Friday, 5 May 2017

AngularJS localhost:port to localhost:differentport No 'Access-Control-Allow-Origin' header is present on the requested resource

Yes, I realize that many people speak of using JSONP or CORS etc..

Currently Website on http://localhost:58954' is AngularJS running on IIS Express making AJAX calls to a NODE/Express Api running on http://localhost:3000

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:58954' is therefore not allowed access.

Seems like over the last few years I recall having to add an iframe to an angular/node app and i needed $sce in that app and then it called a asp.net Web Api in which I needed to add in CORS etc..

I have also done some JSONP with mixed results.

So here is my code

 factory.getAllQuestions = function() {

        var surl = "http://localhost:3000/api/liberty/questions";

        return $http.get(surl).then(function (result) {
            //console.log('service',result.data);
            return result.data;

        });

    }


    return factory;

Can and should I add in JSONP ? If so , where at ? Or what other recommended ways?



via Jeremy Miller

No comments:

Post a Comment