zoukankan      html  css  js  c++  java
  • webform中使用Ajax向web后台传参谨记事项

    webform一般很少用到Ajax的形式进行前后台交互,最近遇到一个问题需要用到Ajax请求,

    被一个简单的地方深深坑了一下,搞了半天找不到问题,就是传参的时候json串的拼写

    先说一下js中的结构写法

    $.ajax({
        url: 'template_detail_modal.aspx/GetTable', //方法一定是静态的
        type: 'post',
        datatype: "json",//可不写
        contentType: "application/json; charset=utf-8",//必须写
        data: {}, //一定是json字符串
        success: function (res) {
           var data=res.d;//返回的结果是一个以d为键的键值对,把返回结果 .d 才可取出返回值
        }
    });

    这里着重强调data里面参数的写法,{}外面一点要加双引号"",键的名字不加,值外面一定加单引号'',在单引号里拼接值,后台才能读到,如 data:"{Name:'"+Name+"'}",

    后台代码:

    一定要引用:using System.Web.Services;

    方法上面要加   [WebMethod],方法一定是静态的

    如下:(这里一定要注意,参数的名字必须和前台传的json串的键名字相同,个数相同,如{name:'"+name+"',age:'"+age+"'}),后台则应该方法名后(string name,string age)


    [WebMethod]
    public
    static string Save(string 参数) { return ""; }
  • 相关阅读:
    Python Semaphore
    Python 互斥锁
    Python 递归锁
    Python GIL锁
    Python 线程调用
    进程与线程
    Python paramiko模块
    Python SocketServer模块
    MonoDevelop with Visual Studio to Linux and Mac OSX maintaining a single code base for all platforms.
    mime大全收集
  • 原文地址:https://www.cnblogs.com/zyg316/p/11303555.html
Copyright © 2011-2022 走看看