I know this sounds bad, but it's necessary.
I have a HTML form on a site with utf-8 charset which is sent to a server which works with the iso-8859-1 charset. The problem is that the server doesn't understand correctly characters we use in Spain like à, á, è, é, ì, í, ò, ó, ù, ú, ñ, ç
and so on. So if I search something like artículo
it answers nothing found with artÃculo
.
I send the form with ajaxform (http://malsup.com/jquery/form/), and the code loks like this:
$(".form-wrap, #pagina").on("submit", "form", function(event){
event.preventDefault();
$(this).ajaxSubmit({
success: function(data){
$("#temp").html(data);
//Handle data in #temp div
$("#temp").html('');
}
});
return false;
});
My problem is: I have no acces to the search server and I cannot change the whole website to iso-8859-1 encodig since this would break other stuff.
I have alredy tried with no succes these scripts:
- http://phpjs.org/functions/utf8_decode/
- http://phpjs.org/functions/utf8_encode/
- http://ecmanaut.blogspot.com.es/2006/07/encoding-decoding-utf8-in-javascript.html
May I be doing everything wrong?
Edit: the escape
function isn't useful for me as it turns these spacial chars into %
prefixed codes which are useless to the server, it then searches for art%EDculo
.
Edit using the encodeURIComponent
function the server understands art%C3%ADculo
. P.S. I just use the word artículo
for testing but the solution it should cover all special chars.