Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get data instantly with ajax?
    primarykey
    data
    text
    <p>I am trying to get data instantly with ajax, but I couldn't. The problem is, when I make a request, response is coming end of the php process. I want to get data after every echo command. So here is the simple example. There is two files, main html file (included javascript) and php file.</p> <p>try.html</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Get Data&lt;/title&gt; &lt;script type="text/javascript"&gt; function makeObject() { var newObject; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ newObject = new ActiveXObject("Microsoft.XMLHTTP"); } else { newObject = new XMLHttpRequest(); } if (newObject.overrideMimeType) { newObject.overrideMimeType('text/xml; charset=UTF-8;'); } return newObject; } var newOne=makeObject(); function getData() { newOne.open('get','process.php',true); newOne.onreadystatechange=function(){ if (newOne.readyState==4) { var box=document.getElementById("queryResult"); box.innerHTML=newOne.responseText; } } newOne.send(null); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="button" id="doit" value="Start Query" onclick="getData();" /&gt; &lt;div id="queryResult"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and process.php</p> <pre><code>&lt;?php echo "1"; sleep(1); echo "2"; sleep(1); echo "3"; sleep(1); echo "4"; sleep(1); echo "5"; ?&gt; </code></pre> <p>when I click the Start Query button, it is waiting 4 seconds and then write 12345 at the same time. I want to write 1 and wait 1 sec then write 2 and wait 1 sec then write 3 etc. How can I do that? Sorry for my English, thanks for the answers :)</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.
 

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