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