[英]409 http error in Couchbase lite in phonegap on iOS
I'm getting a 409 on PUT, POST and DELETE actions. 我在PUT,POST和DELETE操作上得到409。
I have successfully created a database and have PUT one document successfully ONCE. 我已经成功创建了一个数据库,并且一次成功放置了一个文档。 I have tried local and "normal" documents.
我尝试了本地和“正常”文档。 I haven't spend any focus on revisions but think it has to do with this.
我没有花任何精力在修订上,但认为与修订有关。 I only want to save and update this one JSON string in my app - thats it.
我只想在我的应用程序中保存并更新此JSON字符串-就是这样。
It's like I have created this one document to stay forever :-) 就像我创建了这个文档可以永久保存:-)
Will sample code help? 示例代码有帮助吗? I'm really only using Angular's $http.
我真的只使用Angular的$ http。
On a side note: I need a save mechanism in phonegap that is html5 cache-clear resistent. 附带说明:我需要在phonegap中使用html5缓存清除抵抗机制。
You need to check if your document exists first before you update it. 您需要先检查文档是否存在,然后再更新。 that's why it worked the first time and not the second.
这就是为什么它第一次起作用而不是第二次起作用的原因。
config.db.get( "myDocumentID", function(error, doc) {
if (error) {
if (error.status == 404) {
//document does not exist insert it
config.db.put( "myDocumentID", myDocument, function(error,ok) {
if(error) { alert( "error" + JSON.stringify( error ) } else {
alert("success");
}
} )
} else {
alert( "error:" + JSON.stringify( error ) )
}
} else {
//update your document
doc.my_new_key = "value";
config.db.put( "myDocumentID", doc, function(error, ok) {
if( error ) { alert( "error:" + JSON.stringify( error ) ) } else {
alert("success");
}
} );
}
} )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.