Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>you have to make a new object for Ajax transaction named XMLHTTP REQUEST in some browsers and in I.E this is ActiveXObject basically;<br> and this object belong to window object;<br> so the first step is:</p> <pre><code>if ( window.XMLHttpRequest ) { XHR = new XMLHttpRequest(); } else if ( window.ActiveXObject ) { XHR = new ActiveXObject("Microsoft.XMLHTTP"); } else { alert("You Cant see because Your Browser Don't Support Ajax!!!\n Change Your Browser To A Modern One"); } </code></pre> <p>now, you have the right object<br> in next step, there is some methods for XHR object for send and receive you should know:<br> <code>1/ onreadystatechange</code><br> <code>2/readyState</code><br> <code>3/status</code><br> <code>4/open</code><br> <code>5/send</code><br> <code>6/setRequestHeader</code></p> <p>first open a connection with <code>open</code>:</p> <pre><code>XHR.open("POST", url, true); </code></pre> <p>as you know, post is method of sending, and now you have to set the url you want to information send to, for example if you want to send the variable to the <code>test.php</code>, then the url is <code>test.php</code>...<br> true means the request will sent asynchronously.. next is set your request header, because your are using <code>post</code> method, in <code>get</code> method you don't need this:<br></p> <pre><code> XHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); </code></pre> <p>next is sending the request with send method with this format <code>send(name, value)</code>:<br></p> <pre><code>XHR.send('value=' + value); </code></pre> <p>first string 'value=' is the index of $_POST that you will get in php, so in your php code, you'll give this with <code>$_POST['value']</code>, if you set the name to 'name=', in php you have <code>$_POST['name']</code>, be careful that in Ajax send param you have to use <code>=</code> after the name of data, but in php the <code>=</code> is not used... after you sent the request; it's time to mange response:<br></p> <pre><code>XHR.onreadystatechange = function() { if ( XHR.readyState == 4 &amp;&amp; XHR.status == 200 ) { document.getElementById('your target element for show result').innerHTML == XHR.responseText; } } </code></pre> <p>XHR.readyState == 4 and XHR.status == 200 means every thing is O.K.</p> <p>this is the basics of Ajax as you wished for; but there is so many information for Ajax, and either you can use jQuery Ajax method that is so simple and flexible; But as you want I described the basics for you...</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