AngularJS not detecting Access-Control-Allow-Origin header?

后端 未结 9 1209
眼角桃花
眼角桃花 2020-11-28 11:20

I am running an angular app on a local virtualhost (http://foo.app:8000). It is making a request to another local VirtualHost (http://bar.app:8000) using $http.post

相关标签:
9条回答
  • 2020-11-28 11:45

    I was sending requests from angularjs using $http service to bottle running on http://localhost:8090/ and I had to apply CORS otherwise I got request errors like "No 'Access-Control-Allow-Origin' header is present on the requested resource"

    from bottle import hook, route, run, request, abort, response
    
    #https://github.com/defnull/bottle/blob/master/docs/recipes.rst#using-the-hooks-plugin
    
    @hook('after_request')
    def enable_cors():
        response.headers['Access-Control-Allow-Origin'] = '*'
        response.headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, PUT'
        response.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept'
    
    0 讨论(0)
  • 2020-11-28 11:47

    It's a bug in chrome for local dev. Try other browser. Then it'll work.

    0 讨论(0)
  • 2020-11-28 11:48

    Instead of using $http.get('abc/xyz/getSomething') try to use $http.jsonp('abc/xyz/getSomething')

         return{
                getList:function(){
                    return $http.jsonp('http://localhost:8080/getNames');
                }
            }
    
    0 讨论(0)
提交回复
热议问题