Struts2+Jquery Ajax 总是返回error

Cute_Tiger Cute_Tiger 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

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;
}
}

调试代码都能打印出来。

struts.xml代码:


<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>



JS代码:


<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();
}else{
$('label:#locId').html(data.empDto.loc);
}
}
});

});
});
</script>
...全文
评论 2
收藏 已收藏
分享
返回顶部
Cute_Tiger
Ajax 52,778 成员 25,334 内容