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

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

 更新時(shí)間:2016年11月18日 14:37:41   作者:楊明波(Leo Yang)  
這篇文章主要介紹了jQuery post數(shù)據(jù)至ashx實(shí)例詳解的相關(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

今天給大家分享一個(gè)小功能,在jQuery環(huán)境中,Post data to ashx進(jìn)行數(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個(gè)參考需要上傳,top,term。

為了更好在ashx能接收,我們寫一個(gè)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ù):



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

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

 再進(jìn)一步得到top的值:

最后得到的是term的值:

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

相關(guān)文章

最新評(píng)論

荥经县| 伊春市| 甘南县| 嘉禾县| 安西县| 房产| 禄劝| 虞城县| 晋城| 平远县| 垦利县| 镇雄县| 兴和县| 灌阳县| 蓬溪县| 江永县| 广州市| 偃师市| 米泉市| 雅安市| 太仆寺旗| 沂南县| 江门市| 连云港市| 镇平县| 宁南县| 浮梁县| 黄冈市| 宝山区| 连城县| 离岛区| 临朐县| 安丘市| 桓台县| 宁安市| 响水县| 淳安县| 吴堡县| 怀化市| 嘉峪关市| 聂荣县|