Search code examples
ajaxstripquote

Getting rid of \&quot in js file


When i post something with " to a php page, it gets escaped with \&quot ; . To get rid of this in the php file, i've tried str_ireplace, htmlspecialchars_decode and stripslashes, nothing is working. Is there a way i can strip it out after it's returned to the js file?


Solution

  • after you getting response from ajax request use this function to decode

    function htmlspecialchars_decode(text)
    {
       var replacements = Array("&", "<", ">", '"', "'");
       var chars = Array("&amp;", "&lt;", "&gt;", "&quot;", "'");
       for (var i=0; i<chars.length; i++)
       {
           var re = new RegExp(chars[i], "gi");
           if(re.test(text))
           {
               text = text.replace(re, replacements[i]);
           }
       }
       return text;
    }