It is often necessary to pass an array collection to the background when making batch deletions or batch modifications.
At this time, you need to considerHow to submit a JSON array to the background with Ajax in front, and how to get in the background.
Of course, it is also possible to use a splicing string and then split in the background. But there is a better way
First, AJAX submission part
Var jsondata = []; // array, store data collection to be submitted
for (var i = 0; i < row.length; i++) {
// Construct an object
var arr = {
EG_ID: row[i].EG_ID,
EG_MyNum: row[i].EG_MyNum,
}
// store the object in the data set
jsonData.push(arr);
}
$.getJSON("@Url.Action("myDataExchang", "ExchangLogs")", {
// Convert the submitted data into JSON object
jsonData: JSON.stringify(jsonData),
}, function (msg) {
DJMask.msg(msg);
}, "text");
Second, the MVC controller gets data
public ActionResult myDataExchang()
{
/ / Get submitted data
string data = Request["jsonData"];
JavaScriptSerializer jss = new JavaScriptSerializer();
/ / Convert a string to json - "EGLIST object
List<EGList> list = jss.Deserialize<List<EGList>>(data);
// Other operations ...
}
Quote: using system.web.script.serialization;
public class EGList
{
public int EG_ID { get; set; }
public int EG_MyNum { get; set; }
}
JSP login interface code: The corresponding code snippet of the servlet corresponding ajax value: ...
Here is the record I am using ajax to send data to the background, do the corresponding business logic operations backstage after receiving the data; the great God is ignored, the spray would not have...
Reception php background...
Idea: 1, the data to be transferred into the array 2, create a hidden form 3. Traverse the array, create a hidden <input> in the hidden form and assign it 4, submit the form ...
1, HTML part of the code 2, js part 3, background method ...
Since the model binding receives the data is often a problem, so we use the original method of receiving data submitted over with ajax from the front desk: The following sample code: Reception: Backgr...
javascript code Receive parameter code in background Entity class...
front desk: Backstage...
Background sections: // json package used: com.alibaba.fastjson...