zoukankan      html  css  js  c++  java
  • ashx 获取ajax Post到后台json数据

    前台页面代码:

    var json = [{ "Name": "Pavan Kumar Pabothu", "Age": 27, "ID": 361621 }, { "Name": "Reddaiah Raju Padhmaraju", "Age": 27, "ID": 362541 }, { "Name": "Denish Raju Padhmaraju", "Age": 26, "ID": 368941 }];
    $.ajax({
    type: "POST",
    // url: "CommonFiles.aspx/DeleteFiles",
    url: "../data/AjaxTest.ashx",
    //data: "{Id:'" + deleteid + "'}",
    data: { 'myjson': json },
    contentType: "application/json; charset=utf-8",
    dataType: 'json',
    success: function (data) {
    var result = data.d;
    if (result == "error")//失败
    {
    }
    loadFileSort(id);
    }
    });

    Ashx 代码:

    StringBuilder rsb = new StringBuilder();

    var mRequest = context.Request;
    int bytelengg=(int)mRequest.InputStream.Length;
    using (var reader = new StreamReader(mRequest.InputStream,Encoding.UTF8))
    {
    var read = new Char[bytelengg];
    var count = reader.Read(read, 0, bytelengg);
    while (count > 0)
    {
    var str = new string(read, 0, count);
    rsb.Append(str);
    count = reader.Read(read, 0, bytelengg);
    }
    reader.Close();
    reader.Dispose();
    mRequest.InputStream.Close();
    mRequest.InputStream.Dispose();
    }

    然后通过反序列字符串转换成对象。

  • 相关阅读:
    Chp18: Hard
    内存泄漏 和 内存溢出
    Chp4: Trees and Graphs
    trie树--详解
    Tries
    Comparable & Comparator
    memory leak
    8个月从CS菜鸟到拿到Google Offer的经历+内推
    Word Ladder II
    Java垃圾回收机制
  • 原文地址:https://www.cnblogs.com/lanyue52011/p/3298083.html
Copyright © 2011-2022 走看看