# Problem with UTF-8 AJAX search

**URL:** <https://www.ruby-forum.com/t/problem-with-utf-8-ajax-search/49208>\
**Category:** Rails\
**Created:** [November 21, 2005, 11:31pm UTC](https://www.ruby-forum.com/t/problem-with-utf-8-ajax-search/49208 "2005-11-21T23:31:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwjwjw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jwjwjw](https://www.ruby-forum.com/u/jwjwjw)\
**Post date:** [November 21, 2005, 11:31pm UTC](https://www.ruby-forum.com/t/problem-with-utf-8-ajax-search/49208/1 "2005-11-21T23:31:45Z")

</div>

Cheers,

I have an AJAX live search that works like this:

#view  
  
\<%= observe\_field(:search,  
:frequency =\> 1.5,  
:update =\> :results,  
:url =\> { :controller =\> ‘uni’,  
:action =\> :ajax\_suche, },  
:with =\> “‘search=’ +  
escape($F(‘search’))” )%\>

#simplified controller  
def ajax\_suche  
@query = params[:search]  
@profs = Prof.search(@query)  
render(:partial =\> ‘ajax\_suche’)  
end

Further I have the browser\_filter plugin installed.

Searching is working great, the problem is that when I enter Umlauts in  
the  
search field they are not correctly transferred to the controller and  
resulting view.

For example if I enter “Ã¤” in the search field the request parameters  
are  
these:  
Safari:  
{“search”=\>“\344”, “_“=\>”“}  
Firefox:  
{“search”=\>“ï¿½ï¿½”,”_”=\>“”}

In the log I see searches for ‘?’ that will not find results with “Ã¤”  
but  
with “a”.

Seems like a charset mess.

Any hints?

Regards,  
Jonathan

–  
Jonathan W.  
[http://blog.innerewut.de](http://blog.innerewut.de)

---

<div class="post-metadata">

**Author:** ![jwjwjw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jwjwjw](https://www.ruby-forum.com/u/jwjwjw)\
**Post date:** [November 22, 2005, 3:05pm UTC](https://www.ruby-forum.com/t/problem-with-utf-8-ajax-search/49208/2 "2005-11-22T15:05:26Z")

</div>

On 21-nov-2005, at 23:30, Jonathan W. wrote:

> browser\_filter  
> What plugin is it? I cannot find it by googling.

You have to also verify that all of your components treat Unicode  
properly (from the database to HTML and back).

---

<div class="post-metadata">

**Author:** ![jwjwjw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jwjwjw](https://www.ruby-forum.com/u/jwjwjw)\
**Post date:** [November 22, 2005, 5:34pm UTC](https://www.ruby-forum.com/t/problem-with-utf-8-ajax-search/49208/3 "2005-11-22T17:34:30Z")

</div>

> On 21-nov-2005, at 23:30, Jonathan W. wrote:
> 
> > browser\_filter  
> > What plugin is it? I cannot find it by googling.

[http://dev.rubyonrails.org/svn/rails/plugins/browser\_filters/](http://dev.rubyonrails.org/svn/rails/plugins/browser_filters/)

> You have to also verify that all of your components treat Unicode  
> properly (from the database to HTML and back).

Unicode seems to work everywhere else. All my content is UTF-8 in MySQL  
and  
storing/retrieving works normally. Only the AJAX calls fail to treat  
UTF-8  
correcly.

## Regards, Jonathan

Jonathan W.  
[http://blog.innerewut.de](http://blog.innerewut.de)

---

<div class="post-metadata">

**Author:** ![jwjwjw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jwjwjw](https://www.ruby-forum.com/u/jwjwjw)\
**Post date:** [November 23, 2005, 11:30am UTC](https://www.ruby-forum.com/t/problem-with-utf-8-ajax-search/49208/4 "2005-11-23T11:30:27Z")

</div>

Perhaps try,

:with =\> “‘search=’ +encodeURIComponent(escape($F(‘search’)))”

Joshua Sierles

---

<div class="post-metadata">

**Author:** ![jwjwjw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jwjwjw](https://www.ruby-forum.com/u/jwjwjw)\
**Post date:** [November 23, 2005, 2:37pm UTC](https://www.ruby-forum.com/t/problem-with-utf-8-ajax-search/49208/5 "2005-11-23T14:37:14Z")

</div>

> Perhaps try,
> 
> :with =\> “‘search=’ +encodeURIComponent(escape($F(‘search’)))”

Then if I enter ‘ä’ into the search filed I get a search for ‘%E4’. This  
will not find values with ‘ä’.

> Joshua Sierles

## Thanks, Jonathan

Jonathan W.  
[http://blog.innerewut.de](http://blog.innerewut.de)

---

<div class="post-metadata">

**Author:** ![jwjwjw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jwjwjw](https://www.ruby-forum.com/u/jwjwjw)\
**Post date:** [March 5, 2006, 11:06pm UTC](https://www.ruby-forum.com/t/problem-with-utf-8-ajax-search/49208/6 "2006-03-05T23:06:21Z")

</div>

Then you have to decode it again in your controller?

jw wrote:

> > Perhaps try,
> > 
> > :with =\> “‘search=’ +encodeURIComponent(escape($F(‘search’)))”
> 
> Then if I enter ‘ï¿½’ into the search filed I get a search for ‘%E4’. This  
> will not find values with ‘ï¿½’.
> 
> > Joshua Sierles
> 
> ## Thanks, Jonathan
> 
> Jonathan W.  
> [http://blog.innerewut.de](http://blog.innerewut.de)
