XMLHttpRequest
The code is as follows |
Copy Code |
<script type= "Text/javascript" > function Loadxmldoc () { var xmlhttp; if (window. XMLHttpRequest) {//code for ie7+, Firefox, Chrome, Opera, Safari Xmlhttp=new XMLHttpRequest (); } Else {//code for IE6, IE5 Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP"); } Xmlhttp.onreadystatechange=function () { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getElementById ("Txthint"). Innerhtml=xmlhttp.responsetext; } } Xmlhttp.open ("Get", "Filefunction.php?dt=attatchment&u=abc.txt", true); Xmlhttp.send (); } </script> |
Here's a look at jquery+ajax/"target=" _blank ">jquery Ajax applications
JQuery Ajax Events
Ajax requests produce a number of different events, and we can subscribe to these events and process our logic in them. There are two kinds of Ajax events in jquery: Local events and global events.
A local event is defined within a method at each AJAX request, for example:
The code is as follows |
Copy Code |
$.ajax ({ Beforesend:function () { Handle the Beforesend Event }, Complete:function () { Handle the Complete event } // ... }); |
At the same time we can also directly use such as
Jquery.get (URL, [data], [callback]): Asynchronous request using Get method
Load (URL, [data], [callback]): Loads the remote HTML file code and inserts it into the DOM
Jquery.post (URL, [data], [callback], [Type]): Asynchronous request using POST method
These are very good, only suitable for small amount of input if there is a large number of We must use the Ajax-serialize () method method, as follows
The code is as follows |
Copy Code |
Html <form method= "POST" id= "SubmitForm" name= "SubmitForm" ><tr> <td><table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" > <tr> <TD width= "6%" > Mobile phone:</td> <TD width= "21%" ><input name= "Mo" type= "text" class= "INP" id= "Mo" size= ""/></td> <TD width= "8%" align= "right" > Mailbox:</td> <TD width= "21%" ><input name= "Email" type= "text" class= "INP" id= "email" size= "/></td>" <TD width= "44%" ><span class= "Gray" ></span></td> </tr> </table></td> </tr> <tr> <TD height= "align=" "Left" > <textarea name= "bak" cols= "rows=" 5 "class=" Lab "id=" BAK1 "></textarea></td> </tr> <tr> <td><input name= "button" type= "button" class= "but" id= "Buttonajax" value= "submit Message"/> <span class= "Gray" > </span></td> </tr>
</form> $ (' #buttonajax '). Click (function () { //alert ($ (this). Val ()); //checkem () var PostData = $ (' #submitform '). Serialize (); //alert (postdata); $.ajax ({ type: "POST", url: "/postajax.php", data: PostData, success:function (msg) { //alert (msg); if (msg ==1) { alert (' Your question has been submitted successfully! '); } }; }) |