You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Walter Werner <we...@googlemail.com> on 2010/11/15 09:13:40 UTC

jquery-ajax encodeURI Problems

hi

I am new to the mailinglist, hello to everyone. The web Interface of
this mainling list seems not to have any search function, i hope this
problem is new.

When i am trying to make a GET request to one of my couchdb-search-view

			$.get('/mydb/_design/02/_view/search', {startkey:"['foo',0]",
endkey: "['foo',{}]",reduce:true, group:true},
				function(data) {
					alert(data);
				}
			);

I get the error:

{"error":"bad_request","reason":"invalid UTF-8 JSON"}

and my url looks like this:

http://localhost:5984/mydb/_design/02/_view/search?startkey=%5B%27foo%27%2C0%5D&endkey=%5B%27foo%27%2C%7B%7D%5D&reduce=true&group=true

The quotation marks and the [ ] that are needed for the JSON format
are url-encodet inside the $.get function. I do not know how to change
this behaviour. I also tried it with $.post and $.ajax. The same
result. Can anyone help?

Thanks
  Walter

Re: jquery-ajax encodeURI Problems

Posted by Walter Werner <we...@googlemail.com>.
hi Randall

You where absolutely right, with double quotes "foo" it works now. And
i thought it has something to do with couchdb does not understand
url-encoding characters.

let the force be with you ;)
  Walter



2010/11/15 Randall Leeds <ra...@gmail.com>:
> Without testing this myself, I wonder if it's your choice of quotation
> marks. Try using single quotes to delimit the strings and using double
> quotes withing the actual JSON. Such as {startkey: '["foo", {}]'}. If memory
> serves me correctly only double quoted strings are valid JSON. But I'm
> tired, I could be inventing this :)
> On Nov 15, 2010 12:14 AM, "Walter Werner" <we...@googlemail.com> wrote:
>> hi
>>
>> I am new to the mailinglist, hello to everyone. The web Interface of
>> this mainling list seems not to have any search function, i hope this
>> problem is new.
>>
>> When i am trying to make a GET request to one of my couchdb-search-view
>>
>> $.get('/mydb/_design/02/_view/search', {startkey:"['foo',0]",
>> endkey: "['foo',{}]",reduce:true, group:true},
>> function(data) {
>> alert(data);
>> }
>> );
>>
>> I get the error:
>>
>> {"error":"bad_request","reason":"invalid UTF-8 JSON"}
>>
>> and my url looks like this:
>>
>>
> http://localhost:5984/mydb/_design/02/_view/search?startkey=%5B%27foo%27%2C0%5D&endkey=%5B%27foo%27%2C%7B%7D%5D&reduce=true&group=true
>>
>> The quotation marks and the [ ] that are needed for the JSON format
>> are url-encodet inside the $.get function. I do not know how to change
>> this behaviour. I also tried it with $.post and $.ajax. The same
>> result. Can anyone help?
>>
>> Thanks
>> Walter
>

Re: jquery-ajax encodeURI Problems

Posted by Randall Leeds <ra...@gmail.com>.
Without testing this myself, I wonder if it's your choice of quotation
marks. Try using single quotes to delimit the strings and using double
quotes withing the actual JSON. Such as {startkey: '["foo", {}]'}. If memory
serves me correctly only double quoted strings are valid JSON. But I'm
tired, I could be inventing this :)
On Nov 15, 2010 12:14 AM, "Walter Werner" <we...@googlemail.com> wrote:
> hi
>
> I am new to the mailinglist, hello to everyone. The web Interface of
> this mainling list seems not to have any search function, i hope this
> problem is new.
>
> When i am trying to make a GET request to one of my couchdb-search-view
>
> $.get('/mydb/_design/02/_view/search', {startkey:"['foo',0]",
> endkey: "['foo',{}]",reduce:true, group:true},
> function(data) {
> alert(data);
> }
> );
>
> I get the error:
>
> {"error":"bad_request","reason":"invalid UTF-8 JSON"}
>
> and my url looks like this:
>
>
http://localhost:5984/mydb/_design/02/_view/search?startkey=%5B%27foo%27%2C0%5D&endkey=%5B%27foo%27%2C%7B%7D%5D&reduce=true&group=true
>
> The quotation marks and the [ ] that are needed for the JSON format
> are url-encodet inside the $.get function. I do not know how to change
> this behaviour. I also tried it with $.post and $.ajax. The same
> result. Can anyone help?
>
> Thanks
> Walter