1, SPRINGMVC
/*** Request user Information*/@RequestMapping (Value= "Askforusermsg") @ResponseBody PublicJsonarray askforusermsg () {//The unit where the user residesString Unitname =Sysaccessutils.getuser (). Getunit (). GetName (); //Current yearString year =NewSimpleDateFormat ("yyyy"). Format (NewDate ());List<String> msg =NewArraylist<string>(); Msg.add (Unitname); Msg.add (year); Jsonarray usermsg=jsonarray.fromobject (msg); returnusermsg; }
2. Ajax:
Focus Red Section
$. Gajax ({type:"POST", DataType:' JSON ', contentType: "Application/json" , url:GlobalParam.context+ "/einspectionprojectcontroller/askforusermsg", Success:function(data) { var models = eval (data);
//Title Information$ ("#summary"). HTML (models[0]+models[1]+ "External check item"); //Company Name$ ("#company"). Append ("<option value=" +Models[0]+ ">" +models[0]+ "</option>"); //Annual$ ("#year"). Append ("<option value=" +Models[1]+ ">" +models[1]+ "</option>"); } });
AJAX receives JSON data passed by SPRINGMVC