zoukankan      html  css  js  c++  java
  • Ajax

    Ajax 三种方式

    get

    function fun1(){
         $.get(
                "<%=basePath%>file/ajax",
                {"name":"zhansan","age":25},
                function(data){
                    alert(data.name);
                },
                "json"
              
               );
       }
     @RequestMapping(value = "/ajax",method=RequestMethod.GET)
         public @ResponseBody void testajax(HttpServletRequest request, HttpServletResponse response) throws IOException{            
               response.setCharacterEncoding("UTF-8");
              
                try {
                    response.getWriter().write("{"name":"完成"}");
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
    
        }

    post

     function fun2(){
           $.post(
                   "<%=basePath%>file/ajax2",
                    {"name":"zhansan","age":25},
                    function(data){
                        alert(data.name);
                    },
                    "json"
                    
                   );
           }
     @RequestMapping(value = "/ajax2",method=RequestMethod.POST)
         public @ResponseBody void testajax2(HttpServletRequest request, HttpServletResponse response) throws IOException{
                
               response.setCharacterEncoding("UTF-8");
                
               try {
                    response.getWriter().write("{"name":"完成"}");
                    
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
           
        }

    ajax

     function fun3(){
           $.ajax({
                   url:"<%=basePath%>file/ajax2",
                   type:"POST",
                   async:true,
                   data:{"name":"lucy","age":20},
                   success:function(data){
                         alert( "Data Saved: " + data.name );
                   },
    
                    error:function(){
                        alert("Failed");
                    },
                    dataType:"json",
                     
                 });
           }
  • 相关阅读:
    view如何被添加到window上并显示出来
    事件分发机制
    绘制机制
    setContentView
    消息机制——handler
    布局文件是如何被解析的?
    Xamarin.ios引用第三方SDK
    Xamarin.ios——First APP
    UITextView 文本垂直居中
    从NavigationController 下的UITableView中移除 header
  • 原文地址:https://www.cnblogs.com/Jomini/p/9517584.html
Copyright © 2011-2022 走看看