通过更新处理程序将表单提交到couchDB无法正常工作

时间:2013-07-28 12:43:14

标签: couchdb couchapp

我不能通过更新处理程序发布到CouchDB,我不知道我做错了什么。下面是长篇说明。

我使用erica创建了一个应用程序,其中的详细信息主要来自wiki。它工作正常,直到我决定去POST,但服务器端,通过Apache CouchDB wiki Working_with_Forms的更新处理程序

我用erica创建了一个新的'webapp',构建了一个索引(来自wiki的cut-n-paste,有小的改动):

<!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"

然后根据wiki构建了_design文档,如下所示:

{
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推送应用程序,根据链接打开网页,找到表单但是在提交时这是我得到的答案:

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

我已经摆弄了action =“...”属性,甚至把这样的绝对地址:

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

我已经用JSON.stringify()替换了toJSON()。

我重新开始了这个过程并重新完成了项目。无济于事。

我有一种明显的感觉,我已经“失明”了,解决方案可能只是在我眼前,但我看不到它。似乎POST-http请求没有问题,导致服务器在我尝试使用AJAX之前抱怨(忘记了“内容类型”),但这次似乎是内部服务器问题。我没有线索。真。

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

2 个答案:

答案 0 :(得分:2)

我会回答我自己的问题,同时请那些浪费时间的人请求宽恕。

我所做的是通读kanso并了解范围的概念如何适用于这种情况。这是在更新处理程序上使用exports的问题,因此可以通过<form action="/database/_design/designDocument/_update/updateFunction访问它。

为什么我之前没有读过Kan.so?好吧,我的想法是保持简单 - ericacouchapp的继承者我决定继续坚持基础是一个合理的举措。虽然我必须说文档很少,所以通过阅读Kan.so来揭开couchapp建设的魔力,并在此基础上我介绍了其他几个漂亮的概念和技术。我感激地弯下腰来。

我希望所有那些花时间阅读我的长篇内容并且结果是不必要的问题的人将以我的无知来监督。

(现在我只想知道是否有某种管理员/主持人可以处理我的作品以避免将来的时间损失)

答案 1 :(得分:2)

我也遇到了这个错误,正如@ Pea-pod所暗示的那样,导致它失败的原因是没有在couchapp的设计文档中正确定义你的exports。在我们的例子中,它作为list函数无法调用,而是在couchdb日志中显示500 {0}} Type errorpoint is undefined错误。

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

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

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

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

我是否可以建议主持人更改此问题的标题以包含point is undefined,这是在发生此类错误时CouchDB日志中显示的错误,以帮助其他人找到更多错误容易吗?