// 异步的几种基本写法
1 <script type="text/javascript">
4 function fn1(){
5 //get异步访问
6 $.get(
7 "/WEB22/ajaxServlet2", //url地址
8 {"name":"张三","age":25}, //请求参数
9 function(data){ //执行成功后的回调函数
10 //{"name":"tom","age":21}
11 alert(data.name);
12 },
13 "json"
14 );
15 }
16 function fn2(){
17 //post异步访问
18 $.post(
19 "/WEB22/ajaxServlet2", //url地址
20 {"name":"李四","age":25}, //请求参数
21 function(data){ //执行成功后的回调函数
22 alert(data.name);
23 },
24 "json"
25 );
26 }
27 function fn3(){
28 $.ajax({
29 url:"/WEB22/ajaxServlet2",
30 async:true,
31 type:"POST",
32 data:{"name":"lucy","age":18},
33 success:function(data){
34 alert(data.name);
35 },
36 error:function(){
37 alert("请求失败");
38 },
39 dataType:"json"
40 });
41 }
42 </script>