Ajax, Pure Js+jquery

Source: Internet
Author: User

Ajax:asynchronous Javascript and XML asynchronous, JS and XML Interactive page development do not refresh the page, and the server interaction details please refer to the jquery tool guide
Use the technology on the browser side, no refresh, access the page via XMLHttpRequest
Pure JS version----------

if (XMLHttpRequest) {//Determines whether xmlhttprequestxhr= new XMLHttpRequest () is supported;//Create XMLHttpRequest Object}else{xhr= new ActiveXObject ("Microsoft.XMLHTTP"); XMLHttpRequest is not supported, use this method to create}xhr.open ("Get|post", "url", true); Xhr.send (); Start sending the xhr.onreadystatechange= function () {//callback function when the server returns data to the browser triggering method if (xhr.readystate==4)//0 does not call the Open method, 1 means that the Send method is not called , 2 is waiting for the status code and header return, 3 has accepted the partial data, but has not finished, cannot use the object's properties and methods, 4 has been loaded, all the data executed if (xhr.status==200) {//Response status code, indicating that the page executes without error alert ( Xhr.responsetext); Output accepted text}}

  


Write the data in send. and add the request header
Such as

Xhr.setrequestheader ("Content-type", application/x-www-form-urlencoded) xhr.send ("id=123&pwd=456");

-------------------------------------
jquery Edition
Powerful jquery. Just need get page just enough

$.get ("url", {"id": "123", "PWD": 456},function// automatically transmits the parameter as a GET request alert (data)}

Only the post page is required.

$.post ("url", {"id": 123, "pwd": 456},function//POST request alert (data)}

The third kind of wording

$.ajax ({type= "Get" | post,url= "...", data:"parameter", success:function/ /  msg for data received from the server })

Ajax, Pure Js+jquery

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.