Jakub Hubert
Jakub Hubert

Reputation: 336

URL is encoding utf8 chars to % in Oracle APEX js redirect

I have a jQuery code in Execute when Page Loads section of my Oracle APEX page. My page consists of PL/SQL dynamic content, more concretely two select lists that act like an filter. So when selected value of one of those select lists changes redirect with proper page item values is called. JQuery code bellow handles only the second select list that calls page redirect.

var appId = $v('pFlowId');
var pageId = $v('pFlowStepId');

var this_page_link_prefix = 'f?p='+appId+':'+pageId+':::NO:RP:';

$(document).on('change', '#category_select', function() {
    if ($(this).val() != '') {
        var href = this_page_link_prefix+'P'+pageId+'_FILTER_CATEGORY,P'+pageId+'_FILTER_RACE_TYPE:'
        +$(this).val()+','+$('#race_type_select').val()+':';
        console.log(href);
        $(location).attr('href', href);
    }
});

Here I encountered problem that I can not solve by myself. When my filter contains UTF-8 characters like "Ž", url is encoded in % encoding. For example when select list contains "Ženy", my redirected URL looks like this:

f?p=123:5:9348018667019::NO:RP:P5_FILTER_CATEGORY,P5_FILTER_RACE_TYPE:%25C5%25BDeny,1

When I try to console log href variable, it contains proper URL:

f?p=123:5:9348018667019::NO:RP:P5_FILTER_CATEGORY,P5_FILTER_RACE_TYPE:Ženy,1

I think I browsed all application settings and still can not find solution for this. I will appreciate any help.

Upvotes: 0

Views: 2446

Answers (1)

kfinity
kfinity

Reputation: 9091

I have no idea how to control whether UTF-8 characters are displayed in the browser's URL bar. Chrome for example will let me enter them and will display them correctly, but when it sends the request to the server, it percent-encodes them. Try using the F12 developer tools and doing a simple request, e.g. https://www.google.com/search?q=Ženy

So it could be your browser doing it. But what you absolutely can fix is making sure that the P5_FILTER_CATEGORY page item ends up with the correct UTF-8 value and not the percent-encoding. Just add a "Before Header" process or something to do:

:P5_FILTER_CATEGORY := UTL_URL.UNESCAPE (:P5_FILTER_CATEGORY, 'UTF8');

Another thing that might help, which is pretty easy to do, is to edit your page templates and make sure that they're setting the charset that you want in the page header, e.g.

<html><head>
<meta charset="utf-8"/>
....

Finally, you might want to use the browser development tools and check which Content-Type charset APEX is sending in the HTTP header. I don't remember offhand how to change this, but if it's not utf-8, you might want to look into changing it.

Upvotes: 1

Related Questions