First Ajax does not refresh the page submission data, is now widely used, nonsense not to say immediately into the theme!!
Basically the information the browser can receive, Ajax can receive, ex: strings, HTML tags, CSS tags, XML format content, JSON format content, etc. .....
<script>
//IE browser
if (activexobject) {
//Microsoft current AJAX latest version of
var ajax = new ActiveXObject (" msxm12.xmlhttp.6.0 ");
} else{
//Mainstream browser
var ajax = new XMLHttpRequest ();
}
Create HTTP requests
//Open (method, URL, asynchronous, user, password);
Methods: Request Method (Post,get)
//URL: Request Address (is the address to receive data specifically)
//asynchronous: Synchronous or asynchronous request (true is asynchronous, false is synchronous, default is true, can not fill)
//User: (Specify request username, can not fill)
//Password: (Specify request password, can not fill)
ajax.open (' Get ', ' url ');
Ajax.onreadystatechange = function () {
if (ajax.readystate==4) && (ajax.status) ==200) {
alert (AJ Ax.responsetext); The returned data content
}else{
alert (' request failed ');
}
///Send request, content is to be sent, if not, fill in null send
(content);
If you are using the Post method request, set the HTTP header
Ajax.setrequestheader ("Content-type", "application/x-www-form-urlencoded") before send ;
</script>
Ajax onReadyStateChange events receive up to four change states
readystate Return status value:
0 (uninitialized) object established
1 (initialized) The Open method was called
2 (sending data) called Send method
3 (in data transfer) Some data has been returned
4 (completed) Request succeeded
The above is a simple Ajax request principle, I hope to help you learn.