Native JavaScript writes Ajax

Source: Internet
Author: User

Front-end javascript:
Function ajaxget (url, obj)  {    var request;    if (Window. XMLHttpRequest)  {        request = new  XMLHttpRequest ();    } else {         Request = new activexobject (' Microsoft.XMLHTTP '); //  compatible ie    }     request.onreadystatechange = function ()  {         if (request.readystate === 4)  { // 4  request Complete              if (request.status === 200)  { //  200  page successfully loaded                  console.log (Request.responsetext); //  success   Return the resulting text             &nBSP;}  else {                 console.log (request.status); //  failure   Return status code   such as  404             }        } else {             console.log (' Requesting ');         }    }    /*  Parse Parameter  */     str =  '? ';     for (key in obj)  {        str  +=  (key +  ' = '  + obj[key] +  ' & ');    }     str = str.substr (0, str.length - 1);     /*   Send  */    request.open (' GET ',  url + str);    request.send ();} Ajaxget (' ajax.php ', {     ' type ':  ' get ',     ' data ':  ' Test '});  //get-test
Back-end PHP:
<!--ajax.php--><?php echo $_get[' type ']. ‘-‘ . $_get[' data ';

Native JavaScript writes Ajax

This article from "Do not know not to ask" blog, please be sure to keep this source http://mazey.blog.51cto.com/12997993/1975314

Native JavaScript writes Ajax

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.