First case: The foreground incoming string parameter returns a JSON string, or a JSON array
The code is as follows :
Front desk:
$.ajax ({ URL: "Xxx/xxx.action", data: "Id=xxx", Cache:false, async:false, success:function ( Result) { A: The array returned by the receive backend is var data = eval (result); if (typeof (data) = "undefined" && data.length > 0) {for (var i=0;i<data.length;i++) { data[i]["id"]; data[i]["name"]; } } B: The background returns the string, then the direct receive }, error:function () { alert ("Table loading error ..."); } );
Background:
PrintWriter out = Servletactioncontext.getresponse (). getwriter ();/* Back JSON string * /
Out.print (Jarray); Out.flush ();
return null;
Second case: The foreground passes in the JSON array as parameters to interact with the background
Front desk:
function Delcheckeddata () {var array = new Array (); $ (": Checkbox[name= ' chk '][checked=true]"). each (function () {Array.push ({ID: $ (this). Val () }); }) if (Array.Length > 0) {var Gridjson = json.stringify (array, function (key, value) {Retu RN value; }); $.ajax ({url: "/xxx/xxx.action", Cache:false, Data: "idlistjson=" + Gridjson, Async:false, Success:function (Result) {var instdata = eval (result); corresponding processing}, Error:function () {alert ("error ..."); } }); }}
background:
Jsonarray Instarray = jsonarray.fromobject ("parameter"); for (int i = 0; i < instarray.size (); i++) { Jsonobject instj = (jsonobject) instarray.get (i); String sId = instj.get ("id"). toString (); Get the ID to do the appropriate action }
Ajax in Javascript implements foreground-to-background interaction