angularjs - 为什么我的请求 POST by $resource 是一个 OPTIONS

标签 angularjs

我使用的代码如下,在 Coffeescipt 中:

request_with_token =
  get:
    method: "JSONP",
    params:
      token: app["token"]
  save:
    method: "POST",
    params:
      token: app["token"]

$rootScope.API = "http://0.0.0.0:5200/1.0"

$scope.ajaxAccountUpdate = $resource($rootScope.API + "/account/update.json",
  { callback: "JSON_CALLBACK" }, request_with_token )

user = $scope.user
$scope.ajaxAccountUpdate.save user, (resource) ->
  $scope.show_message(resource)

但是在我的日志中我有一个选项而不是帖子

[07/Feb/2013 16:50:48] "OPTIONS /1.0/account/update?callback=JSON_CALLBACK&token=mytoken HTTP/1.1" 200 -

谢谢

最佳答案

可能是因为您向提供 HTML 的网站发出请求,从而导致“跨源资源共享”CORS 飞行前检查。这是一项安全功能:

了解更多信息:http://www.html5rocks.com/en/tutorials/cors/

关于angularjs - 为什么我的请求 POST by $resource 是一个 OPTIONS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14755464/

相关文章:

angularjs - 在动态生成的 AngularJS 指令中访问父 Controller

javascript - Anugar JS - 项目推送到对象数组后 View 中不刷新

javascript - AngularJS - 当使用切片两次时数据不可用时,ng-repeat 显示空单元格

javascript - 如何在ng-repeat中更改单个div的内容

javascript - 使用 Angularjs 根据 json 中的值检查复选框

javascript - AngularJS - 缩小错误

javascript - 将 API 调用中收集的值从第一个方法传递到同一对象中的第二个方法

javascript - AngularJS 的 $routeProvider templateUrl 总是使用 Express 返回 404

javascript - 具有功能的 Angular ng-show

ruby-on-rails - Rails 4 找不到文件 'angular-rails-templates'