日期:2014-05-16 浏览次数:20789 次
public class JsonAction extends EmpBaseAction{
private EmpDto empDto;
private String loc;
HttpServletRequest request;
public String findLoc() throws IOException, SQLException{
request = ServletActionContext.getRequest();
String deptno = request.getParameter("deptno");
System.out.println("deptno-----------------------------------------------"+deptno);
loc = EmpDtoDao.findLocByDeptno(deptno);
System.out.println("loc-----------------------------------------------"+loc);
empDto.setLoc(loc);
return "success";
}
public EmpDto getEmpDto() {
return empDto;
}
public void setEmpDto(EmpDto empDto) {
this.empDto = empDto;
}
}
<package name="json" extends="json-default" namespace="/emp">
<action name="jsonAction" class="com.sisj.action.JsonAction" method="findLoc">
<result name="success" type="json">
<param name="contentType">
text/html
</param>
<param name="includeProperties">
empDto\.loc
</param>
</result>
</action>
</package>
<script type="text/javascript" >
$(function(){
$("#deptno").change(function(){
var deptno = $('#deptno').val();
$.ajax({
type: "POST",
url: "jsonAction.action",
data: {"deptno": deptno, "method": "findLoc"},
dataType: 'json',
// async: true,
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("获取失败。");
alert("http请求的状态:"+XMLHttpRequest.status);//200
alert("XMLHttpRequest对象的处理状态:"+XMLHttpRequest.readyState);//4
alert(textStatus);//parsererror
},
success: function(data){
alert("SUCCESS");
if(data.empDto.loc == undefined){
$('label:#locId').empty();