Couchbase-Lite-PhoneGap: я получаю «Статус 400 — неверный запрос», когда пытаюсь создать документ _design (представление)

Я имел дело с Couchbase-Lite-PhoneGap-Plugin. Я пытаюсь создать проектный документ в эмуляторе Android, используя REST API. Но каждый раз я получаю сообщение 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();

person efkan    schedule 16.11.2014    source источник


Ответы (1)


Я установил свой плагин с помощью команды cordova plugin add com.couchbase.lite.phonegap

Однако плагин был бета-версией и прежней версией на plugins.cordova.io.
Затем я попытался удалить и переустановить плагин с помощью команды

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

Я смог пройти этот путь.

person efkan    schedule 18.11.2014