javascript: passing parameter with special characters to function without being replaced

ساخت وبلاگ

Vote count: 0

I need to pass to javascript function some data that has special characters like

#228;

A full string will look like this

Bundesland Kärnten

My javascript function looks like this

function my_fumc(arg){ console.log(arg);
} 

If i call this function in the following way

my_fumc('Bundesland Kärnten')

I get in console

Bundesland Kärnten

Instead of

Bundesland Kärnten

So, the

Kä

being replaced.

I tried different things to solve this problem. 1.Passing a variable as parameter

my_var = 'Bundesland Kärnten';
my_fumc(my_var)

It works but i don't think it's a good solution.2. I also tried using encodeURI() function like

my_fumc(encodeURI('Bundesland Kärnten'))

As a result i get:

Bundesland%20K%C3%A4rnten

I prepared a very simple jsfiddle to show how javascript behaves when passing special characters to function.

Please, help me find a solution.

asked 34 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 226 تاريخ : دوشنبه 11 ارديبهشت 1396 ساعت: 15:51