Note that there are some explanatory texts on larger screens.

plurals
  1. POonreadystatechange function not being called
    text
    copied!<p>For some reason, onreadystatechange call back function is not being called in asynchronous mode. I tested the post in synchronous mode and confirmed that post itself is working fine (commented out testing code I used to check post in synchronous mode). The problem occurs both in safari and firefox latest version. Can someone please tell me what I am doing wrong here? Thank you.</p> <pre><code> &lt;html&gt; &lt;head&gt; &lt;script&gt; function recordScore(str) { if (str.length==0) { return; } xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="http://hellworld3.appspot.com/findcountry"; var params = "screenname="+document.getElementById("screenname1").value+"&amp;score="+document.getElementById("score1").value; alert("params: "+params); xmlHttp.open("POST",url,true); xmlHttp.onreadystatechange = function() { alert("entered call back function. readstate value is: "+xmlHttpreadyState+". Response Text is: "+xmlHttp.responseText); if (xmlHttp.readyState==4) { document.getElementById("message").innerHTML=xmlHttp.responseText; } } xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded") xmlHttp.send(params); //Testing code for synchronous mode //alert("Http get status is: "+xmlHttp.status); //alert("Http ready state value is: "+xmlHttp.readyState); //alert("Http get response text is: "+xmlHttp.responseText); //document.getElementById("message").innerHTML=xmlHttp.responseText; } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="testform"&gt; Screename: &lt;input type="text" id="screenname1" name="screenname"&gt; &lt;br/&gt; Score: &lt;input type="text" id="score1" name="score" onchange="recordScore(this.value)"&gt; &lt;br/&gt; &lt;p id="message"&gt;test&lt;/p&gt; &lt;input type="submit" value="Submit"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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