Ajax send and receive request _ajax related

Source: Internet
Author: User
Tags html tags

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.