Problem: Accumulating in the general handler (. ashx) [index=' B '] value difficulty: Foreground gets JSON value background resolution resolved:#region the value of the index=b exists in the JSON objectfunctionAjaxgetsum() { var arr = [];$("input[index= ' B ']"). each (function() { var arrobject = {}; var TempVal = $ (This). Val (); if (!$.gstr.isempty (TempVal)) { //The company's own encapsulated JS $.gstr.isempty (ST) to determine whether St is empty, return true/false arrobject[ "invalue"] = TempVal; Arr.push (arrobject); } }); var jsonstring = json.stringify (arr); //Convert to JSON-type string $.post ("Handlersum.ashx", {jsonvar:jsonstring}, function (data) { alert (data); })}//#endregion
Using System;Using System.Collections.Generic;Using System.Linq;Using System.Web;Using Newtonsoft.json;Using Newtonsoft.Json.Linq;Using Newtonsoft.Json.Converters;Namespace train_first.ajax_rpc{ ///<summary> Summary description of Handlersum ///</summary> PublicClass Handlersum:ihttphandler{ Publicvoid ProcessRequest (HttpContext context) { Context. Response.ContentType ="Text/plain"; string ss = Context. request.form["Jsonvar"];Get an array of lessons JSON strings passed by the foreground Jarray JavaScript = (Jarray) jsonconvert.deserializeobject (ss);An array of JSON strings obtained by deserialization String stringsum =""; for (int i =0; I < JavaScript. Count; i++) { Jobject obj = (jobject) javascript[i]; String outvalue = obj["Invalue"]. ToString ();Converts an array of deserialized JSON strings into objects Stringsum + = Outvalue; } context. Response.Write (Stringsum); } public bool isreusable { get { return false; } }}} /span>
Ajax Call (value-sent) generic handler (. ashx)