Note that there are some explanatory texts on larger screens.

plurals
  1. PO$_GET the value of (&) with AJAX
    text
    copied!<p>I have three codes the first one is <code>html</code>:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type = "text/javascript" src = "AJAX.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form method = "GET" &gt; &lt;input type = "text" id ="a" &gt;&lt;br&gt; &lt;input type = "text" id = "b"&gt;&lt;br&gt; &lt;input type = "button" value ="click" onclick = "process()"&gt;&lt;br&gt; &lt;textarea id = "underbutton" &gt;&lt;/textarea&gt;&lt;br&gt; &lt;/form&gt; &lt;body&gt; &lt;/html&gt; </code></pre> <p>Now javaScript (AJAX) :</p> <pre><code>function process() { if(xmlHttp.readyState==0 || xmlHttp.readyState==4){ a = document.getElementById("a").value; b = document.getElementById("b").value; xmlHttp.onreadystatechange = handleServerResponse; xmlHttp.open("GET","file.php?a="+a+"&amp;b="+b,true); xmlHttp.send(); } } function handleServerResponse (){ if(xmlHttp.readyState==4 &amp;&amp; xmlHttp.status==200) { response = xmlHttp.responseText; document.getElementById("underbutton").innerHTML = response ; } } </code></pre> <p>Now php file :</p> <pre><code>&lt;?php echo $_GET['a'].'&lt;br&gt;'; echo $_GET['b'].'&lt;br&gt;'; ?&gt; </code></pre> <p>everything is working but the problem is when I type in the first texbox (a) the word <code>hello</code> and the second (b) the code <code>&amp;</code> and click the button ; it must print out <code>hello&amp;</code>.<br> but it prints <code>hello</code>!!<br> just <code>hello</code> without <code>&amp;</code>.<br></p> <p>I noted that I was sending to php file is this : <code>file.php?a=hello&amp;b=&amp;</code>.<br> the last <code>&amp;</code> must be <code>%26</code> </p> <p>So to print out <code>&amp;</code> I must send : <code>file.php?a=hello&amp;b=%26</code>.<br> </p> <p>How can I fix that ??</p>
 

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