狐狸.fox 2017-08-27 22:56 采纳率: 0%
浏览 26

Angular Rest Web2py

i can't conect my server web2py restful with angular Ajax, but if i set the url in my browser it's fine it work , but i cant in angular ajax =(

Link of Angular

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script>
<script src="https://code.angularjs.org/1.3.16/angular-route.min.js"></script>

Mi code in my server web2py (Controller)

@request.restful()
def api(): 
    response["Access-Control-Allow-Origin"] = "*"
    response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
    response["Access-Control-Max-Age"] = "1000"
    response["Access-Control-Allow-Headers"] = "*"
    response.view = 'generic.json'
    def GET():
            print "asdasds"
            return dict(content="JAJAJAJAJA")

    return dict(GET=GET)

and mi AJax in angular url= Address:port/nameProject/controller/action

  app.controller('controlVentas',  function( $http) {
  var app = this; 
  app.CargarLlave=function(){ 
       var respuesta=$http.get("http://127.0.0.1:8000/Hoteles/ControlMSR/api");
       respuesta.success(function(data){ 
                   alert( "OK"); 
              });
       respuesta.error(function(data, status, headers, config){
                  alert( "NOOOOO"); 
           });  
  } 
});

error of angular

XMLHttpRequest cannot load http://127.0.0.1:8000/Hoteles/ControlMSR/api. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:57734' is therefore not allowed access.
  • 写回答

2条回答 默认 最新

  • weixin_33743661 2017-08-27 23:42
    关注

    The proper way to set response headers is via response.headers, not directly on the response object. For example:

    response.headers["Access-Control-Allow-Origin"] = "*"
    
    评论

报告相同问题?