0

我一直在处理 Couchbase-Lite-PhoneGap-Plugin。我尝试使用 REST API 在 Android 模拟器中创建设计文档。但是每次我收到status: 400 - Bad request消息时,我都找不到我的错误。

我的代码如下;

var cblUrl = "";   
var dbName = "user"; 

var app = {

    initialize: function() {
        this.bindEvents();
    },

    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },

    onDeviceReady: function() {

        if(window.cblite) {

            window.cblite.getURL(function(err, url) {
                if(err) {
                    console.log("error launching Couchbase Lite: " + err);
                } else {
                    console.log("Couchbase Lite running at " + url);
                    cblUrl = url;
                }
            });

        } else {
            console.log("error, Couchbase Lite plugin not found.");
        }

        // jQuery Main function
        $(function() {

            $("#connect").on("tap", function() {

                $.ajax({
                    url: cblUrl + '_all_dbs',
                    type: 'GET',                   
                    success: function (data, textStatus, xhr) {

                        if (data.indexOf(dbName) == -1) {  // db doesn't exist

                            // create a database (bucket)
                            $.ajax({
                                url: cblUrl + dbName,
                                type: 'PUT',                   
                                async: true,
                                success: function (data, textStatus, xhr) {

                                    console.log(xhr.status);

                                },
                                error: function (xhr, statusText, errorThrown) {
                                    console.log(xhr.status);
                                }
                            }); 

                        } else { 
                            console.log("db exists");
                        }

                    },
                    error: function (xhr, statusText, error) {
                        console.log(xhr.status);
                    }
                });

            }); // #connect tap

            // create button tap event
            $("#create").on("tap", function() {

                var view  =  {
                        "language" : "javascript",
                        "views" : {
                            "view_user" : {
                                "map" : "function(doc) {if (doc.username) {emit(doc.username, null)}}"
                            }
                        }
                    }

                // ** create VIEW **
                $.ajax({
                    url: cblUrl + dbName + "/_design/users",
                    type: 'PUT', 
                    data: view,
                    success: function (data, textStatus, xhr) {
                        console.log(xhr.status);
                    },
                    error: function (xhr, statusText, error) {
                        console.log(xhr.status);
                    }
                });

            }); 
        }); // main jQuery function
    }, // onDeviceReady
}; 

app.initialize();
4

1 回答 1

0

我已经使用命令安装了我的插件 cordova plugin add com.couchbase.lite.phonegap

但是,该插件是 beta 版,并且是plugins.cordova.io的旧版本。
然后我尝试使用命令卸载并重新安装插件

cordova plugin add https://github.com/couchbaselabs/Couchbase-Lite-PhoneGap-Plugin.git

我能够通过这种方式。

于 2014-11-18T07:23:55.567 回答