Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript AJAX return special characters
    primarykey
    data
    text
    <p>I've been trying to return special characters from an AJAX request to a PHP script.</p> <p>The responding character string : abcde1’2’3’4’5“6”7–8é9é10’11’12’13ñ14ñ15’16ñ17ñ18 19 20é21é22í23ñ24ñ25’26ñ27ó28ú29’fghij</p> <p>Using a JavaScript alert, it displays: abcde1â2â3â4â5â6â7â8é9é10â11â12â13ñ14ñ15â16ñ17ñ18 19 20é21é22í23ñ24ñ25â26ñ27ó28ú29âfghij</p> <p>The code is below:</p> <p><strong>HTML File:</strong></p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"/&gt; &lt;title&gt;&lt;/title&gt; &lt;script src="js/phpTest.js" charset="ISO-8859-1" type="text/javascript"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input id="Submit1" type="submit" value="submit" onclick=" initXHR();return false;" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>JS File:</strong></p> <pre><code>var xhr; //;charset=ISO-8859-1 function initXHR() { getXHRobj(); xhr.open('POST', 'phpinfo.php', true); xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Content-length", 10); xhr.setRequestHeader("Connection", "close"); xhr.send(""); return false; } function getXHRobj() { if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else if (window.ActiveXObject) { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } else { throw new Error("Ajax is not supported by this browser"); } xhr.onreadystatechange = function XHRresp() { if (xhr.readyState == 4) { if (xhr.status &gt;= 200 &amp;&amp; xhr.status &lt; 300) { document.write("1. " + xhr.responseText); } else { alert(xhr.responseText); } } } } </code></pre> <p><strong>And PHP file:</strong></p> <pre><code>&lt;?php header("Content-Type: text/html;charset=ISO-8859-1"); print "abcde1’2’3’4’5“6”7–8é9é10’11’12’13ñ14ñ15’16ñ17ñ18 19 20é21é22í23ñ24ñ25’26ñ27ó28ú29’fghij"; ?&gt; </code></pre> <p>Thank you, deDogs</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload