Script does not code utf8


I'm trying to send a parameter by url from javascript, and that parameter has accents. I try to encode to utf8 and then I code the url but apparently, it does not do it as it should (excuse foolishness but avoiding tildes is not an option).

echo "<script>";
echo "$(document).ready(function(){";
echo "$('#filtrobusqueda').on('keyup', function() {";
echo "var palabra = document.getElementById('buscarpalabra').value;";
//echo "palabra = utf8_encode(palabra);"
//echo "palabra = encodeURI(palabra)";
$dato = "palabra";
echo    "$('#mostrar').load('mostrar.php?parametro='+". (urldecode(utf8_encode($dato))).");";

echo   "});";
echo "});";
echo "</script>";

I already tried with those who are commented and does not do anything; I tried to code with the functions of php (urldecode and utf8_encode) but it does not recognize it either.

How could I solve it without having to remove the accents with another function?

asked by Erik 18.12.2018 в 07:08

1 answer


I have the same problem with a field that has the symbol "%", and I send it with the function urlencode () .


<a target="_blank" href="MostrarQuery.php?variable1='.$ciclo.'&variable2='.urlencode($fila['remark']).'">
answered by 18.12.2018 в 11:59