北京 工业网站建设公司排名,抖音代运营合作策划书,网络营销简介,给客户建设网站税率一般我们使用Jquery提交数据到Asp.net程序都有两种方法,今天我再介绍一种方法.以下是详细描述: 1)使用Get请求的方式,将参数接在请求Url的后面.例如: http://www.google.com.hk/search?qjquerypost 获取参数的方法:在Asp.net中可以使用Request.QueryString[q]来获…一般我们使用Jquery提交数据到Asp.net程序都有两种方法,今天我再介绍一种方法.以下是详细描述: 1)使用Get请求的方式,将参数接在请求Url的后面.例如: http://www.google.com.hk/search?qjquerypost 获取参数的方法:在Asp.net中可以使用Request.QueryString[q]来获取参数. 2)使用Jquery的Form.js插件中的ajaxForm方法或者 自己提交之前构造一个Form在使用ajaxForm提交数据.例如: $(document).ready(function(){ //简单模式 $(#btnSubmit1).click(function() { $(#form1).ajaxForm(); }); //复杂模式 $(#btnSubmit1).click(function() { var options { method: POST, url: ajaxSP.aspx, after: function(response) { alert(response.id); } }; $((#form1).ajaxForm(options); }); }); 获取参数的方法:在Asp.net中可以使用Request[q]来获取参数. 3)那今天我想说一下第三种做法. 就是结合jQueryJsonAsp.net并且利用Newtonsoft.Json.Net20.dll来进行Json数据的双向转换. jQuery代码: $.ajax({ url: AjaxSP.aspx, data: {type:DoOpenClickStart,id:1001}, type: post, dataType: json, contentType: application/json; charsetutf8, success: function(data) { alert(ID data.ID ;Type data.Type); }, error: function(xhr) { alert(失败); } }); Asp.net代码: 1.准备一个Entity类. publicclass AjaxSPE { /// /// 处理类型 /// publicstring Type { get; set; } /// /// 要处理的记录ID /// publicstring ID { get; set; } } 2.Asp.net接受参数以及输出结果的核心代码: //01.接受传入的参数(记得先引用Dll:Newtonsoft.Json.Net20.dll) string requestJson string.Empty; using(StreamReader reader new StreamReader(Context.Request.InputStream)) { requestJson reader.ReadToEnd(); } AjaxSPE ajax2 JsonConvert.DeserializeObject(requestJson, typeof(AjaxSPE)) as AjaxSPE; 结果数据如下图: //02.传出结果Json数据,并输出到客户端. Response.ClearContent(); Response.ContentType application/json; AjaxSPE ajax new AjaxSPE(); ajax.Type dddd; ajax.ID 1009; string jsonString Jsoner.JsonConvert.SerializeObject(ajax, Jsoner.Formatting.Indented); //输出Json数据到Content Response.Write(jsonString); Response.Flush(); Response.End(); 结果如下图: 好了,就介绍到这里.最然不是什么复杂的技术研究,也有它方便的地方. 转载于:https://www.cnblogs.com/gym333/archive/2012/08/27/2659050.html