日期:2014-05-20 浏览次数:20658 次
function getstaffinfo(){ var staffid=$("#staffid").val(); $.ajax({ type: "post", url: "getInfoById.action?staffid="+$("#staffid").val(), contentType:"application/json;charset=utf-8", error:function(){ alert("err"); }, success: function(result) { alert("success"); var json=eval(result); var staffname= json.staffname; var staffcareer = json.staffcareer; document.getElementById("staffname").value=staffname; document.getElementById("staffcareer").value=staffcareer; }}); }
private Map<String, String> result; //........省略get/set public String getInfoById(){ List<Staff> list = this.getSalaryService().findSalaryTableById(this.getStaffid()); Map<String, String> result2 =new HashMap<String, String>(); result2.put("staffname", list.get(0).getName()); result2.put("staffcareer",list.get(0).getCareer()); this.setResult(result2); return SUCCESS; }
<tr> <td colspan="6"><font color="red">*</font>员工工号</td> <td><input type="text" name="salarytable.staffid" id="staffid" onblur="getstaffinfo()"></td> <td colspan="6">员工姓名</td> <td><input type="text" id="staffname" value="" /></td> <td colspan="6">员工职位</td> <td><input type="text" id="staffcareer" value="" /></td> </tr>
<package name="salary2" extends="json-default"> <result-types> <result-type name="json" class="org.apache.struts2.json.JSONResult"/> </result-types> <action name="getInfoById" class="main.salary.action.SalaryAction" method="getInfoById"> <result name="json"></result> </action> </package> </struts>