zoukankan      html  css  js  c++  java
  • .net 前端传值和后端接收的几种方式

    第一种:GET传参(常用):

      get传参方式就是链接?后写上参数和数据用&拼接.

    第二种:POST传参(常用):

      这种传参方式可以GET POST同时传,在链接上加参数后台用get方式接收,POST传的数据,后台用POST数据接收.

      例如:

    $.ajax(
    
       {
    
           url: ("FinancialCenter.aspx?timestamp={0}").format(new Date().getTime()),
    
          type: 'POST',
    
         dataType: 'json',

    async:true, timeout:
    10000, data: { Action: "UpdateItemCraft", Callback: "true", ItemId: id, UpdateValue: NewValue }, success: function (resultData) { } });

    第三种和第二种有点相像,但是第三种不传变量名,将数据转成JSON来传:

     例:

      $.ajax({
      type: 'Post',
      url: url,
      data: JSON.stringify(searchStr),
      dataType: 'json',
      success: function (resultJsonData) {
    
      });

    这个时候后端接收值的时候,就不能用GET和POST方式接收了,而是要用:

      Request.InputStream来接收。

     

     Stream postedStream = context.Request.InputStream;
      using (StreamReader reader = new StreamReader(postedStream, Encoding.UTF8))
      {
        this._postedStr = reader.ReadToEnd();
      }
    

      

    第四种:就是SUBMIT的方式进行get和post数据传输(在服务端控件中,用得多)

    第五种:变种SUBMIT方式上传数据(这种其实是PostBack方式上传数据,webForm开发的用得多)

    接收参数:

    get pos 接收方式我就不讲了,没有意思,Model方式接收也不讲了。以下是无Model对应时,个人认为的最好接收方式:

    当接收来自前台的参数时,前台参数无变量,就是一个整体,而且整体没有可对应的对象时,用JObject处理最佳

     JObject jPostStr = JsonConvert.DeserializeObject(_postedStr) as JObject;
                    string typecode = jPostStr["TypeCode"].ToString();
  • 相关阅读:
    close connection error java.sql.SQLRecoverableException: IO Error: Broken pipe
    Mysql 备份与恢复
    MACBOOK 破解wifi密码
    MAC 安装homebrew
    Linux(CentOS / RHEL 7) 防火墙
    ORA-01031: insufficient privileges
    Oracle登录认证
    ORA-12162: TNS:net service name is incorrectly specified
    lsnrctl: .... cannot restore segment prot after reloc: Permission denied
    CentOS / RHEL 配置yum源
  • 原文地址:https://www.cnblogs.com/Xanthus/p/9435546.html
Copyright © 2011-2022 走看看