ajax交互struts返回json
type="josn",就是返回json
type="redirect",就是返回页面
ajax一般是接受json,故result--》 type="json"
ajax接受HTML,故result——》type="redirect" 也可
struts-default 是sturts核心中的,json是struts-json-plugin.jar中的,这个插件包也继承了struts-default,只是拓展了struts返回json的要求
<package name="remindInfo" extends="json-default" namespace="/remind"> <action name="queryRemindInfo" class="remindInfoAction" method="queryRemindInfo"> <result type="json"> <param name="contentType">application/jsonparam> <param name="root">rspStrparam> result> action> <action name="remindInfoAction_*" class="remindInfoAction" method="{1}"> <result type="json"> <param name="contentType">application/jsonparam> <param name="root">rspStrparam> result> <result name="viewDetailRemindInfo">/itm/salefollow/remindInfoDetails.jspresult> <result name="viewDetailWeiXinRemindInfo">/itm/salefollow/remindInfoWXDetails.jspresult> action> <action name="getMap" class="orderManageAction" method="getMap"> <result type="json"> <param name="contentType">application/jsonparam> <param name="root">resultparam> result> action> package>
// 微信交單提醒查询
public String queryWeixinRemind() {
if (null != agentid && !"".equals(agentid)) {
agentid = agentid.substring(1);
}
// 获取 下次联系时间的前10分钟
Date now = new Date(); //当前时间
Calendar calendar = Calendar.getInstance(); //得到日历
calendar.setTime(now);//把当前时间赋给日历
calendar.add(calendar.MINUTE, 10); //设置为后n分钟 负数为前n分钟
Date dBefore = calendar.getTime(); //得到后n分钟的时间
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
String strCurrentDate= formatter.format(dBefore);
String sql = "from RemindInfoEntity where agentid='" + agentid + "' and status='1' and remindtype='" + remindtype + "' and PresentationMethod='2'";
List
if(list != null) {
rspStr = JsonUtils.bean2Json(list);
}
return SUCCESS;
}
//微信交單通知
function weixinRemind() {
$.ajax({
type: "POST",
url:"${pageContext.request.contextPath}/remind/remindInfoAction_queryWeixinRemind.action",
data: {
agentid: agentId,
remindtype:"2"
},
beforeSend: function() {},
success: function(data) {
var obj = eval("(" + data + ")");
$("#weixinRemindDiv").empty();
/*if(obj!=null && obj.length>0){
var viewInput="新进客户微信交单"+obj.length+"笔";
var confirmInput = "查看详情";
$("#weixinRemindDiv").append(viewInput);
$("#weixinRemindDiv").append(" ");
$("#weixinRemindDiv").append("
");
$("#weixinRemindDiv").append("
");
$("#weixinRemindDiv").append(confirmInput);
document.getElementById("weixinRemindId").style.display="block";
}*/
for(var i = 0 ; i < obj.length; i++) {
var viewInput="新进客户微信交单1笔";
var confirmInput = "查看详情";
$("#weixinRemindDiv").append(viewInput);
$("#weixinRemindDiv").append(" ");
$("#weixinRemindDiv").append("
");
$("#weixinRemindDiv").append("
");
$("#weixinRemindDiv").append(confirmInput);
$("#weixinRemindDiv").append("
");
$("#weixinRemindDiv").append("
");
document.getElementById("weixinRemindId").style.display="block";
/*if (obj[i]["reason"] != "") {
$("#weixinRemindDiv").append("
");
var content = ""+ (i+1) + "." + obj[i]["reason"]+" ";
$("#weixinRemindDiv").append(content);
var orderno = obj[i]["orderno"];
var viewInput = "处理";
$("#weixinRemindDiv").append(viewInput);
$("#weixinRemindDiv").append(" ");
var ignoreInput = "忽略";
$("#weixinRemindDiv").append(ignoreInput);
$("#weixinRemindDiv").append(" ");
var endRemindInput ="结束提醒";
$("#weixinRemindDiv").append(endRemindInput);
$("#weixinRemindDiv").append("
");
$("#weixinRemindDiv").append("
");
document.getElementById("weixinRemindId").style.display="block";
}*/
}
}
});
}