First of all I have read CouchDB Document Update Handlers (in-place updates) and have adopted the code in the answer to that question.
I have an update handler that takes a query string amount and is supposed to add that to doc.count of a given document. Instead of adding the two amounts, it merely lists them. E.G. 5+5=55. Also adding a parseInt() to doc.count yields an error message:
{"error":"render_error","reason":"undefined response from update function"}
My update handler is:
"countPlus": "function(doc, req) {var amount1 = doc.count; var amount2 = parseInt(req.query.amount); doc.count = amount1 + amount2; return [doc, doc.count]; }"
The js that handles the requests is:
if (count != null && count != NaN && count != 0) {
var currentCounter = $.ajax({
type: "POST",
async: false,
url: $(location).attr("href").replace("_show/action", "_update/countPlus") + "?amount=" + count,
contentType : "application/json",
dataType: "json"
});
var currentCountResponse = currentCounter.responseText;
alert(currentCountResponse);