角$资源不改变方法 [英] Angular $resource dont change method

查看:126
本文介绍了角$资源不改变方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I''m尝试配置与Angular.js和CouchDB的一个简单的服务

I''m trying to configure a simple service with Angular.js and Couchdb

var App = angular.module('myapp', ['ngResource'], function(){});

App.factory('products', ['$resource', function($resource) { 

  var Products = $resource(
      'http://localhost\\:5984/products/_all_docs',
      {},
      { all: { method: 'GET'} }
  );

  return {
    all: function() {
        return Products.all();
    }
  };
}]);

当我打电话products.all()从我的控制器总是我得到

when i call products.all() from my controller always i get

OPTIONS /productos/_all_docs HTTP/1.1
Host: localhost:5984
Connection: keep-alive
Access-Control-Request-Method: GET
Pragma: no-cache
Cache-Control: no-cache
Origin: http://localhost:8000
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17
Access-Control-Request-Headers: accept, origin, x-requested-with
Accept: */*
DNT: 1
Referer: http://localhost:8000/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: es-419,es;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

响应头

HTTP/1.1 405 Method Not Allowed
Server: CouchDB/1.2.1 (Erlang OTP/R14B04)
Date: Tue, 29 Jan 2013 22:15:31 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 69
Cache-Control: must-revalidate
Allow: GET,HEAD,POST

Request URL:http://localhost:5984/productos/_all_docs
Request Method:OPTIONS
Status Code:405 Method Not Allowed

我无法想象,为什么发送OPTIONS方法时,我没有宣布!

I can not imagine why send an OPTIONS method when I dont have declared that!

推荐答案

选项方法来源于做一个跨起源请求。见<一href=\"http://stackoverflow.com/questions/1256593/jquery-why-am-i-getting-an-options-request-insted-of-a-get-request\">Jquery:为什么我会收到一个OPTIONS请求insted的GET请求的?。即使主机和要求是本地主机,端口是不同的(5984,8000)。请参见同一产地的主机,不同端口JS

The OPTIONS method comes from doing a cross origin request. See Jquery: Why am I getting an OPTIONS request insted of a GET request?. Even though both the host and the request is to localhost, the ports are different (5984, 8000). See Same origin host, different ports in JS.

这篇关于角$资源不改变方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆