The wording of Ajax

Source: Internet
Author: User

Ajax refers to a network request that is sent without refreshing the page, that is, an asynchronous request.

The notation in JS:

varxmlhttpreq=NULL;//declares an empty object to load the XMLHttpRequest objectfunctionSendajax () {if(Window. XMLHttpRequest) {//browsers other than ie5,6xmlhttpreq=NewXMLHttpRequest (); }Else{//ie5,6 is the introduction of XMLHttpRequest objects in a ActiveXObject way .xmlhttpreq=NewActiveXObject (' Microsoft.XMLHTTP '); } xmlhttpreq.open (' GET ', ' test.php ',true); Xmlhttpreq.onreadystatechange=function(){        if(xmlhttpreq.readystate===4){        if(xmlhttpreq.status===200) {document.getElementById (' ResText '). innerhtml=Xmlhttpreq.responsetext; }}} xmlhttpreq.send ();}

In jquery, the details of the AJAX request are encapsulated, providing Ajax, get, and post methods.

$.ajax ()

1 $.ajax ({2URL: ' text.php ',3Type: ' Get/post ',//Request Method4Data: ",//data sent to the server, if the GET request is appended to the URL5DataType: ' JSON ',//expected data types returned by the server6Successfunction(){},//callback function for successful request7Errorfunction(){}//callback function for request failure8});

$.get ()

 1  $.get (url , [, Data][,callback][,type]);  2  3  $ (' #send '). Click (function   () { 4  $.get (' get1.php ' ,{ 5  username:$ (' #username ') Span style= "color: #000000"). Val (),  6  content:$ (' #content ' 

$.post () and $.get () are both structured and used in the same way

 1  $ (' #send '). Click (function   () { 2  $.post (' get1.php ' ,{ 3  username:$ (' #username ' 

However, there is a big difference between a POST request and a GET request:

1.get requests Place parameters behind URLs, and post requests do not, and post requests are more secure.

2.get requests have a limit on the size of the transmitted data, and there is no theoretical limit to post requests.

3.get requested data will be cached by the browser.

The wording of Ajax

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.