jquery autocomplete not returning results with é

2019-06-05 02:53发布

问题:

I'm having a hard time with a JQquery Autocomplete script. It works fine until I perform a search with a non-UTF8-character in the search query.

For instance: search query "test" succesfully returns results like "test", "test é" etc but when I add the é to the search query it doesn't give any results any more: (query "test é" returns no results).

When I call the php script that performs the query and returns the the results as an json-array it does show me the correct output: "[{"id":"1230","value":"Test \u00e9"}]", it just on the HTML-page that te drop-down with the results is not given anymore.

any advice on this is hugely appreciated.

Walter

回答1:

I -finally- found it. And, as usual, it's pretty simple:

In the javascript part where I cal the JSON-script I replaced "q: escape(request.term)" by "q: encodeURI(request.term)". That solved my issue!

$("#field")
.autocomplete({
    source: function( request, response ) {
        $.getJSON("./ajax/json_search.php", {
            object_type: "artists",
            q: encodeURI(request.term)
            }, response);
        }
})