我试图挽救一个骨干模式CouchDB的,所以我已经覆盖了保存
方法与阿贾克斯requet到CouchDB的:
$。阿贾克斯({
键入:把',
网址:http://127.0.0.1:5984/movies/+ this.get('身份证'),
的contentType:应用/ JSON的,
数据:JSON.stringify(this.toJSON()),
成功:函数(){
的console.log(ASDF);
},
失败:函数(){
的console.log('测试');
}
});
请求被发送,但是当我看的CouchDB登录的jQuery似乎发送选项
HTTP方法,而不是 PUT
:
[信息] [< 0.1601.0>] 127.0.0.1 - - 选项/影片/ 862 405
和CouchDB的发送 405
HTTP响应code(不允许的方法)。任何想法?
修改 这里是头发送到CouchDB的:
选项/电影/ 862 HTTP / 1.1
主持人:127.0.0.1:5984
接受:text / html的,是application / xhtml + xml的,应用程序/ XML; Q = 0.9,* / *; Q = 0.8
接受语言:EN-US,EN; Q = 0.5
接受编码:gzip,紧缩
接收字符集:ISO-8859-1,UTF-8,Q = 0.7,*; Q = 0.7
保持活动:115
连接:保持活动
原产地:HTTP://本地主机:8888
访问控制请求-方法:PUT
访问控制请求报头:内容类型
解决方案
还有的沙发上,DB ..的 https://github.com/janmonschke/backbone-couchdb
I'm trying to save a Backbone model in couchdb so I've overridden the save
method with a ajax requet to couchdb:
$.ajax({
type: 'PUT',
url: 'http://127.0.0.1:5984/movies/' + this.get('id'),
contentType: 'application/json',
data: JSON.stringify(this.toJSON()),
success: function() {
console.log('asdf');
},
failure: function() {
console.log('test');
}
});
The request is sent but when I look at the couchdb log jQuery seems to send a OPTIONS
HTTP method instead of PUT
:
[info] [<0.1601.0>] 127.0.0.1 - - 'OPTIONS' /movies/862 405
and couchdb sends a 405
HTTP Response code (method not allowed). Any Ideas?
Edit Here are the headers sent to CouchDB:
OPTIONS /movies/862 HTTP/1.1
Host: 127.0.0.1:5984
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Origin: http://localhost:8888
Access-Control-Request-Method: PUT
Access-Control-Request-Headers: content-type
解决方案
There's a backbone connector for couch-db.. https://github.com/janmonschke/backbone-couchdb