jquery中ajax格式
<script type="text/javascript">
 function fn1(){
 //get異步訪問
 $.get(
 "/WEB22/ajaxServlet2", //url地址
 {"name":"張三","age":25}, //請求參數
 function(data){ //執行成功后的回調函數
 //{\"name\":\"tom\",\"age\":21}
 alert(data.name);
 },
 "json"
 );
 }
 function fn2(){
 //post異步訪問
 $.post(
 "/WEB22/ajaxServlet2", //url地址
 {"name":"李四","age":25}, //請求參數
 function(data){ //執行成功后的回調函數
 alert(data.name);
 },
 "json"
 );
 }
 function fn3(){
 $.ajax({
 url:"/WEB22/ajaxServlet2",
 async:true,
 type:"POST",
 data:{"name":"lucy","age":18},
 success:function(data){
 alert(data.name);
 },
 error:function(){
 alert("請求失敗");
 },
 dataType:"json"
 });
 }
</script>
轉載于:https://www.cnblogs.com/ZhangHaiBK/p/8988610.html
總結
以上是生活随笔為你收集整理的jquery中ajax格式的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: PHP单元测试使用
- 下一篇: Docker 安装 For CentOS
