通过更新处理程序将表单提交到bedDB无效 [英] Submitting form to couchDB through update handler not working

查看:65
本文介绍了通过更新处理程序将表单提交到bedDB无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过更新处理程序发布到CouchDB,并且我不知道自己在做什么错。下面是详细描述。

I can not post to CouchDB through an update handler and I do not know what I am doing wrong. Below follows the long description.

我使用erica创建了一个应用程序,详细信息主要来自Wiki。在我决定进行POST之前,它一直运行良好,但是根据 Apache CouchDB wiki Working_with_Forms

I created an app using erica, with details taken primarily from the wiki. It worked fine until I decided to go for POSTing, but server-side, through an update handler according to Apache CouchDB wiki Working_with_Forms

我用erica创建了一个新的 webapp,并构造了一个索引( Wiki,并进行了一些小的改动):

I created a new 'webapp' with erica, constructed an index (cut-n-paste from the wiki, with small alterations):

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Minimal Form</title>
</head>

<body>
<div id="contact-form">
  <form id="contact" method="post" action="/mydatabase/_design/mydesigndoc/_update/postForm" enctype="multipart/form-data">
    <fieldset>
        <label for="name">name</label>
        <input type="text" name="name" placeholder="Full Name" title="Enter your name" class="required">

        <label for="phone">phone</label>
        <input type="tel" name="phone" placeholder="+1 (555) 555-5555" required="" pattern="\+?[0-9 )(-]+">

        <label for="email">e-mail</label>
        <input type="email" name="email" placeholder="you@example.org" title="e-mail address" class="required email">

        <label for="blog">blog</label>
        <input type="url" name="url" placeholder="http://">

        <label for="message">message</label>
        <textarea name="message"></textarea>

        <input type="submit" name="submit" class="button" id="submit" value="submit">
    </fieldset>
  </form>
</div>


我将表单属性 action = 更改为: htttp:// localhost:5984 / DBNAME / _design / DESIGNDOCID / _update / UPDATENAME 并添加 enctype = multipart / form-data

I altered the form-attribute action= to: htttp://localhost:5984/DBNAME/_design/DESIGNDOCID/_update/UPDATENAME and added enctype="multipart/form-data".

然后,根据Wiki,构造了 _design 文档,如下所示:

Then a _design document was constructed, according to the wiki, like this:

{
updates: {
    postForm: function(previous, request) {

        /* during development and testing you can write data to couch.log
    log({"previous": previous})
    log({"request": request})
    */
    var doc = {}
    if (!previous) {
            // there's no existing document _id as we are not using PUT
            // let's use the email address as the _id instead
            if (request.form && request.form.email) {
                // Extract the JSON-parsed form from the request
                // and add in the user's email as docid
                doc = request.form
                doc._id = request.form.email
            }
        }
        return [doc, toJSON({
            "request": request,
            "previous": previous,
            "doc": doc
        })]
    }
}
}

将其放置在 ddoc文件夹中,用erica推送应用程序,根据链接打开网页,找到表格,但是提交后,这是我得到的答案:

This was placed in the "ddoc"-folder, pushed the app with erica, opened the webpage according to the link, found the form but when it was submitted this is what answer I got:

{"error":"unnamed_error","reason":"(new TypeError(\"point is undefined\", \"/usr/share/couchdb/server/main.js\", 1475))"}

我摆弄了action = ...属性,甚至使用了绝对地址,如下所示:

I have fiddled around with the action="..." attribute, even put absolute adress like this:

http://localhost:5984/mydatabase...

我已将toJSON()替换为JSON.stringify()。

I have replaced the toJSON() with JSON.stringify().

我已经重新启动了该过程,并再次完成了该项目。徒劳无功。

I have restarted the process and done the project it all over again. To no avail.

我有种明显的感觉,我已经盲目了,解决方案可能就在我眼前,但我看不到。似乎POST-http-request没有问题,导致服务器在我尝试AJAX之前曾抱怨(忘记 content-type),但这一次似乎是服务器内部问题。而且我没有任何线索。真的。

I have the distinct feeling that I have gone "blind", and that the solution is probably just in front of my eyes but I cannot see it. Seems like there is no problem with the POST-http-request, cause the server has complained before when I have experimented with AJAX (forgot "content-type"), but this time it seems to be internal server problems. And I do not have a clue. Really.

总而言之,问题是:有人可以帮助我吗?

All in all, the question is: Can somebody help me? Please.

推荐答案

我也遇到了此错误,由@ Pea-pod暗示的是什么导致了错误,但未定义在沙发应用程序的设计文档中正确地<< c $ c>出口。在我们的例子中,它是作为列表函数无法调用的,而是显示了500错误,并显示 Type error point is undefined 在beddb日志中。

I also ran into this error and what causes it, as hinted at by @Pea-pod, is not defining properly your exports in the couchapp's design documents. In our case it was as list function that couldn't be called and instead displayed a 500 error with Type error and point is undefined in the couchdb log.

我们使用 kanso ,在app.js中我们没有不需要列表文件。我们有:

We use kanso and in the app.js we hadn't required the list file. We had:

module.exports = {
    rewrites: require('./rewrites'),
    views: require('./views'),
    shows: require('./shows')
};

将其更改为以下内容可以解决问题:

Changing it to the following solved the problem:

module.exports = {
    rewrites: require('./rewrites'),
    views: require('./views'),
    shows: require('./shows'),
    lists: require('./lists')
};

我可以建议主持人更改此问题的标题以包括点未定义,这是在发生此类错误时在CouchDB日志中显示的错误,以便帮助其他人更轻松地找到它?

Can I suggest to a moderator to change the title of this question to include point is undefined which is the error that shows up in the CouchDB log when this type of error is made, in order to help others find it more easily?

这篇关于通过更新处理程序将表单提交到bedDB无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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