zoukankan      html  css  js  c++  java
  • C#--Ajax模板

    前台Ajax传递数据

    
                $.ajax({
                    url: "/organization/organizationTree",//发送请求的地址  
                    type: "POST",// POST,默认是GET  
                    dataType: 'json',//根据返回数据类型可以有这些类型可选:xml html script json jsonp text
                    async: true,//是否异步请求
                    data: {//请求携带的参数信息  
                        name: "张三",
                        sex: 1
                    },
                    success: function (data) {//请求成功  
                        alert("请求成功,返回:" + data);
                    },
    
                });
    
    
    -------------------------------------------------------------------------------------------------------------------------------------------------
    
            $.ajax({
                url: "/organization/organizationTree",//发送请求的地址  
                type: "POST",// POST,默认是GET  
                dataType: 'json',//根据返回数据类型可以有这些类型可选:xml html script json jsonp text
                async: true,//是否异步请求
                data: {//请求携带的参数信息  
                    name: "张三",
                    sex: 1
                },
                beforeSend: function () {//发送请求前执行此函数  
                    alert("请求发送前执行");
                },
                success: function (data) {//请求成功  
                    alert("请求成功,返回:" + data);
                },
                error: function () {//请求出错  
                    alert("请求出错了!");
                },
                complete: function () { //请求完成  
                    alert("请求完成!");
                },
    
            });
    
    
    
    !!!!!!!!!!!!jquery ajax经常用到的一个工具函数!!!!!!!!!!!!
            //完整实例如:(表单html结构不在写)
            $("form").on("submit", function () {
                var url = this.action;   //可以直接取到表单的action
                var formData = $(this).serialize();
                $.post(url, formData,
                    function (data) {
                        //返回成功,可以做一个其他事情
                        console.log(data);
                    }, 'json');
    
                //阻止表单默认提交行为
                return false
            })
    
    
            参考:https://www.cnblogs.com/zhumengke/articles/9564980.html
    
    

    后台接受数据

    
    public ActionResult organizationTree()
            {
                var name = Request["name"];
                var sex = Request["sex"];
                string msg = sex == "1" ? "男" : "女";
    
                return Json(msg, JsonRequestBehavior.AllowGet); ;
            }
    
    
  • 相关阅读:
    ABAP接口用法
    监听textarea数值变化
    The first step in solving any problem is recognizing there is one.
    Wrinkles should merely indicate where smiles have been.
    God made relatives.Thank God we can choose our friends.
    Home is where your heart is
    ABAP跳转屏幕
    Python 工具包 werkzeug 初探
    atom通过remote ftp同步本地文件到远程主机的方法
    Mongodb学习笔记一
  • 原文地址:https://www.cnblogs.com/jsll/p/12445058.html
Copyright © 2011-2022 走看看