Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript function that use XMLHttpRequest
    text
    copied!<p>I have a simple Javascript function that send asyncronous POST request to 2 different php script. Here's a simple code:</p> <pre><code>&lt;script type="text/javascript"&gt; function send(oForm, what) { var ios3 = oForm.ios3.checked; var ios4 = oForm.ios4.checked; var ios5 = oForm.ios5.checked; var id = oForm.id.value; if (what == confirm) { if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}// code for IE7+, Firefox, Chrome, Opera, Safari else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}// code for IE6, IE5 xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { var output = xmlhttp.responseText; if (output != ""){document.getElementById("debug").innerHTML=output; document.getElementById(id).style.display = 'none';} } } xmlhttp.open("POST","ajax/confirm.php",true); xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp.send('id=' + encodeURIComponent(id) + '&amp;ios3=' + encodeURIComponent(ios3) + '&amp;ios4=' + encodeURIComponent(ios4) + '&amp;ios5=' + encodeURIComponent(ios5)); } if (what == remove) { if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}// code for IE7+, Firefox, Chrome, Opera, Safari else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}// code for IE6, IE5 xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { var output = xmlhttp.responseText; if (output != ""){document.getElementById("debug").innerHTML=output; document.getElementById(id).style.display = 'none';} } } xmlhttp.open("POST","ajax/confirm.php",true); xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp.send('id=' + encodeURIComponent(id) + '&amp;ios3=' + encodeURIComponent(ios3) + '&amp;ios4=' + encodeURIComponent(ios4) + '&amp;ios5=' + encodeURIComponent(ios5)); } </code></pre> <p>} </p> <p>and I call this function with these simple input button (without the "\" I have added these for php echo)</p> <pre><code>&lt;input type=\"button\" id=\"submit\" value=\"Confirm\" onclick=\"send(this.form, confirm)\" /&gt; &lt;input type=\"button\" id=\"remove\" value=\"Remove\" onclick=\"send(this.form, remove)\" /&gt; </code></pre> <p>Can someone explain me why it works only for the 1st button?</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