我無法通過更新處理程序發佈到CouchDB,我不知道我做錯了什麼。以下是詳細描述。通過更新處理程序無法正常工作提交表單到couchDB
我使用erica創建了一個應用程序,其中的細節主要來自wiki。它工作得很好,直到我決定去張貼,但服務器端,通過更新處理根據Apache CouchDB wiki Working_with_Forms
我創建了一個新的「Web應用程序」與埃裏卡,構建索引(切正膏會從維基,有小的改變):
<!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="[email protected]" 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"
。
然後,_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」 -folder,推該應用的ERICA,打開網頁根據鏈路發現的形式,但它被提交時這是回答我:
{"error":"unnamed_error","reason":"(new TypeError(\"point is undefined\", \"/usr/share/couchdb/server/main.js\", 1475))"}
我已經用行動擺弄周圍=「...」屬性,甚至把絕對ADRESS這樣的:
http://localhost:5984/mydatabase...
我用json.stringify()替換了toJSON()。
我已重新啓動該過程,並重新完成了項目。無濟於事。
我有明顯的感覺,我已經「失明」,並且解決方案可能只是在我眼前,但我看不到它。似乎POST-http請求沒有問題,導致服務器在我嘗試使用AJAX(忘記「content-type」)之前抱怨過,但這次它似乎是內部服務器問題。我沒有線索。真。
總而言之,問題是:有人能幫助我嗎?請。
我知道這是一個很長的描述。正如我已閱讀本網站上的各種帖子,我發現最常見的評論是問題/描述是模糊的和/或需要闡述。所以我做了。 它太長/詳細?我應該減少以獲得答案嗎? –
我知道這是一個古老的問題,但自從你問:是的。請減少描述。只包括相關的細節。我已經爲你做了一些編輯。 – Flimzy