最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery post數(shù)據(jù)至ashx實例詳解

 更新時間:2016年11月18日 14:37:41   作者:楊明波(Leo Yang)  
這篇文章主要介紹了jQuery post數(shù)據(jù)至ashx實例詳解的相關(guān)資料,需要的朋友可以參考下
public void ProcessRequest(HttpContext context)
    {
      context.Response.ContentType = "application/json";
      context.Response.ContentEncoding = Encoding.UTF8;

      Stream inputStream = context.Request.InputStream;
      Encoding encoding = context.Request.ContentEncoding;
      StreamReader streamReader = new StreamReader(inputStream, encoding);

      string strJson = streamReader.ReadToEnd();

      Param p = JsonConvert.DeserializeObject<Param>(strJson);

      int top = Convert.ToInt32(p.Top);
      string term = p.Term;

      
      //var result = ...
      //context.Response.Write(result.ToJson());
    }

Source Code

jQuery post數(shù)據(jù)至ashx

今天給大家分享一個小功能,在jQuery環(huán)境中,Post data to ashx進行數(shù)據(jù)交互。

參考下面代碼示例:

$.ajax({
           url: '<%= ResolveUrl("~/Handlers/xxx.ashx") %>',
              dataType: "json",
              type: "POST",
              contentType: "application/json; charset=utf-8",
              data: JSON.stringify({
                top: 10,
                term: request.term
              }),
              success: function (data) {
                //...
              }
            });


jQuery的Post值是使用type: "POST",上傳的數(shù)據(jù)類型為contentType: "application/json; charset=utf-8"。

從代碼示例中,它有2個參考需要上傳,top,term。

為了更好在ashx能接收,我們寫一個model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Param
/// </summary>
namespace Insus.NET
{
  public class Param
  {
    private int _top;
    public int Top
    {
      get { return _top; }
      set { _top = value; }
    }


    private string _term;

    public string Term
    {
      get { return _term; }
      set { _term = value; }
    }
  }
}


在ashx處理程序中,我們可以同下面這樣接收Post過來的數(shù)據(jù):



下面我們嘗試在實際環(huán)境中,Post一個數(shù)據(jù)如 “1628”,在FireFox的firebug看到傳送結(jié)果如下:

在ashx中,接收到的結(jié)果如下:

 再進一步得到top的值:

最后得到的是term的值:

 感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論

兴安县| 恭城| 军事| 略阳县| 资源县| 乌苏市| 丰城市| 黔江区| 云南省| 清水河县| 汝南县| 福泉市| 丹东市| 奉化市| 怀仁县| 昌吉市| 广东省| 嘉兴市| 大埔县| 寻乌县| 阿坝| 金溪县| 昭苏县| 城步| 兴文县| 塔城市| 宁夏| 长白| 唐山市| 梁山县| 华容县| 镇巴县| 平昌县| 米林县| 邯郸县| 陈巴尔虎旗| 襄城县| 长顺县| 抚州市| 平乡县| 平定县|