jQuery post數(shù)據(jù)至ashx實例詳解
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。
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看到傳送結果如下:
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
- Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法總結
- jquery中$.post()方法的簡單實例
- javascript jQuery $.post $.ajax用法
- jQuery get和post 方法傳值注意事項
- jQuery中ajax的post()方法用法實例
- jquery ajax post提交數(shù)據(jù)亂碼
- Jquery AJAX POST與GET之間的區(qū)別
- jquery post方式傳遞多個參數(shù)值后臺以數(shù)組的方式進行接收
- jquery中get,post和ajax方法的使用小結
- jquery向.ashx文件post中文亂碼問題的解決方法
相關文章
jQuery中animate()的使用方法及解決$(”body“).animate({“scrollTop”:top})
這篇文章主要介紹了關于jQuery中animate()的使用方法及解決$("body").animate({"scrollTop":top})不被Firefox支持的問題,文中介紹的非常詳細,相信對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。2017-04-04jquery.lazyload 實現(xiàn)圖片延遲加載jquery插件
看到了淘寶產品介紹中,圖片是在下拉滾動條時加載,這是一個很不錯的用戶體驗。減少了頁面加載的時間了,也減輕了服務器的壓力,就查了下用JQuery..2010-02-02使用JQuery快速實現(xiàn)Tab的AJAX動態(tài)載入(實例講解)
這篇文章主要介紹了使用JQuery快速實現(xiàn)Tab的AJAX動態(tài)載入(實例講解)需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12jQuery+CSS3實現(xiàn)仿花瓣網固定頂部位置帶懸浮效果的導航菜單
這篇文章主要介紹了jQuery+CSS3實現(xiàn)仿花瓣網固定頂部位置帶懸浮效果的導航菜單,可實現(xiàn)頁面向下滑動后導航欄橫向懸浮并固定在頂部的功能,涉及jQuery事件響應及頁面元素屬性動態(tài)修改相關操作技巧,需要的朋友可以參考下2016-09-09