5

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:

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.

Falk
  • 469
  • 1
  • 7
  • 19
  • 1
    Try good old [`escape`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape) to encode your strings. Better yet, find the one who runs that server and [hit them with a chicken](https://www.youtube.com/watch?v=y3ln6mp0HNM) – georg Apr 08 '16 at 08:59
  • 1
    Possible duplicate of [How do I transcode a Javascript string to ISO-8859-1?](http://stackoverflow.com/questions/2283829/how-do-i-transcode-a-javascript-string-to-iso-8859-1) – Matthew Herbst Apr 08 '16 at 09:05
  • @georg Yes i would hit him with a chicken (but a living one) if I could, escape isn't useful as it leaves the char code prefixed with an `%`. @matthew-herbst I'm not sure if it really is a duplicate, I have alredy tried the answers from that question but it doesn't help. – Falk Apr 08 '16 at 10:17

2 Answers2

2

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.

You can try setting form accept-charset:

<form accept-charset="iso-8859-1">
....
</form>
Ginden
  • 5,149
  • 34
  • 68
-4

Finally the one who runs that server gave us access to the server and we made an utf-8 compatible php script. So I don't care any more.

Falk
  • 469
  • 1
  • 7
  • 19