jQuery post數(shù)據(jù)至ashx實(shí)例詳解
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。
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過來(lái)的數(shù)據(jù):
下面我們嘗試在實(shí)際環(huán)境中,Post一個(gè)數(shù)據(jù)如 “1628”,在FireFox的firebug看到傳送結(jié)果如下:

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
- Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法總結(jié)
- jquery中$.post()方法的簡(jiǎn)單實(shí)例
- javascript jQuery $.post $.ajax用法
- jQuery get和post 方法傳值注意事項(xiàng)
- jQuery中ajax的post()方法用法實(shí)例
- jquery ajax post提交數(shù)據(jù)亂碼
- Jquery AJAX POST與GET之間的區(qū)別
- jquery post方式傳遞多個(gè)參數(shù)值后臺(tái)以數(shù)組的方式進(jìn)行接收
- jquery中g(shù)et,post和ajax方法的使用小結(jié)
- jquery向.ashx文件post中文亂碼問題的解決方法
相關(guān)文章
jQuery中animate()的使用方法及解決$(”body“).animate({“scrollTop”:top})
這篇文章主要介紹了關(guān)于jQuery中animate()的使用方法及解決$("body").animate({"scrollTop":top})不被Firefox支持的問題,文中介紹的非常詳細(xì),相信對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-04-04
jquery.lazyload 實(shí)現(xiàn)圖片延遲加載jquery插件
看到了淘寶產(chǎn)品介紹中,圖片是在下拉滾動(dòng)條時(shí)加載,這是一個(gè)很不錯(cuò)的用戶體驗(yàn)。減少了頁(yè)面加載的時(shí)間了,也減輕了服務(wù)器的壓力,就查了下用JQuery..2010-02-02
使用JQuery快速實(shí)現(xiàn)Tab的AJAX動(dòng)態(tài)載入(實(shí)例講解)
這篇文章主要介紹了使用JQuery快速實(shí)現(xiàn)Tab的AJAX動(dòng)態(tài)載入(實(shí)例講解)需要的朋友可以過來(lái)參考下,希望對(duì)大家有所幫助2013-12-12
jQuery+CSS3實(shí)現(xiàn)仿花瓣網(wǎng)固定頂部位置帶懸浮效果的導(dǎo)航菜單
這篇文章主要介紹了jQuery+CSS3實(shí)現(xiàn)仿花瓣網(wǎng)固定頂部位置帶懸浮效果的導(dǎo)航菜單,可實(shí)現(xiàn)頁(yè)面向下滑動(dòng)后導(dǎo)航欄橫向懸浮并固定在頂部的功能,涉及jQuery事件響應(yīng)及頁(yè)面元素屬性動(dòng)態(tài)修改相關(guān)操作技巧,需要的朋友可以參考下2016-09-09
jQuery滾動(dòng)條插件nanoscroller使用指南
本文給大家介紹的nanoScrollerJS是一款使用簡(jiǎn)單方式實(shí)現(xiàn) Mac OS X Lion 系統(tǒng)滾動(dòng)條效果的jQuery插件。該滾動(dòng)條插件利用原生的滾動(dòng)條可以工作在 iPad、iPhone 和一些 Android Tablets上。2015-04-04
jQuery實(shí)現(xiàn)郵箱下拉列表自動(dòng)補(bǔ)全功能
在一些網(wǎng)站我們經(jīng)常看到當(dāng)我們要輸入郵箱的時(shí)候,還沒有填寫完,就會(huì)出現(xiàn)一系列下拉列表,幫助我們自動(dòng)補(bǔ)全郵箱,怎么實(shí)現(xiàn)的呢?今天下面給大家分享基于jquery實(shí)現(xiàn)郵箱下拉列表自動(dòng)補(bǔ)全功能,一起看看吧2016-09-09
jQuery 學(xué)習(xí)入門篇附實(shí)例代碼
這篇文章比較不錯(cuò),更重要的是一些實(shí)例代碼,對(duì)于想學(xué)習(xí)jquery的朋友是個(gè)不錯(cuò)的資料。2010-03-03







