Hi experts
I have a weird problem. I'm not really sure where to ask for help so please point me to the right place in case this is the wrong group.
A little explaining first:
Besides containing a lot of helpful information on Swiss species it enables biologists to export the data and also import own data and reexport it combined with other data in the couchapp.
Switzerland means the used language is German. German contains lots of special characters like ä, ö, ü, Ä, Ö, Ü.
So the data in this couchapp is full of them. And also: The names used in JSON for fields, for instance: "Artname vollständig": "Pulsatilla vulgaris Mill. (Gewöhnliche Küchenschelle)".
Coming from a relational background I realize that these characters can be troublesome, especially when used as field names but in this use-case preventing it from happening would make the app a whole lot more complicated and less intuitive for the users.
The issue
In short:
When the couchapp is served from cloudant and the field name "Artname vollständig" is read from an input using "getAttribute" and encoded using "encodeURIComponent" (this happens in the browser), the result is: "Artname%20vollsta%CC%88ndig". This is wrong and breaks my app. When the couchapp is served on my local machine the result is: "Artname%20vollst%C3%A4ndig" which is the desired result.
More detailed:
I have code that runs on an event after the user has chosen data to export. The code loops through checkboxes and creates an array of objects containing (also) the field names. The code gets the field names from an attribute named "feld" of the checkbox (I've omitted unrelevant classes and additional attributes of the input)
<div class="checkbox">
<label>
<input type="checkbox" feld="Artname vollständig">Artname vollständig
</label>
</div>
running this code:
console.log("this.getAttribute('feld') = " + this.getAttribute('feld'));
gives as expected: "$(this).attr('feld') = Artname vollständig"
If while looping, I run:
console.log('encodeURIComponent("Artname vollständig") = ' + encodeURIComponent("Artname vollständig"));
the answer is correct: 'encodeURIComponent("Artname vollständig") = Artname%20vollst%C3%A4ndig'
But if I run:
console.log("encodeURIComponent(this.getAttribute('feld')) = " + encodeURIComponent(this.getAttribute('feld')));
the answer is: "encodeURIComponent(this.getAttribute('feld')) = Artname%20vollsta%CC%88ndig". But only when the app is served from cloudant. On my local development machine the result is correct.
The evironment
On my local machine:
Windows 8
apache couchdb 1.4.0
chrome 29.0.1547.76 m
Proposed solution
offered by jasonslyvia on the above mentioned stackoverflow thread: "seems like erlang server, can you manage to add a Content-Type:text/html;charset=utf-8 header when your server send responses"
Unfortunately I'm too much of a noob to understand how to do this under the circumstances (couchapp hosted on
cloudant.com).
I've searched quite a while but haven't found any information relating to couchapps that seems to nail the problem (mainly information on how to control encoding when serving list-functions).
Help is much appreciated!
Alex