,

Jquery special characters

  • When post() or get() are used, some special characters (Latin, Roman, or other) are returned broken or unrecognizable.
  • I couldn't find a perfect solution to that, but here is a function that can kludge the problem and it is very quick to run.
  • Be aware that Javascript isn't syncronous, so when this code is running, other parts of the JS code can be triggered at the same time, this can cause some issues that are hard to fix.
function jxReplaceSpecialChars(data)
    {
    do
        {
        data=data.replace(/£/,'£');
        data=data.replace(/¬/,'¬');
        data=data.replace(/"/,'"');
        data=data.replace(/&/,'&');
        data=data.replace(/>/,'>');
        data=data.replace(/&lt;/,'<');
        }
    while(
          data.indexOf('£')>=0 ||
          data.indexOf('¬')>=0 ||
          data.indexOf('"')>=0 ||
          data.indexOf('&')>=0 ||
          data.indexOf('>')>=0 ||
          data.indexOf('<')>=0
          )

    return data;
    }

Comments

24th Jun 11 Chris S
JS is synchronous. http://stackoverflow.com/questions/2035645/when-is-javascript-synchronous