一、目标
通过Ajax 请求后台数据
二、代码
1、前台ftl文件,通过URL请求后台数据,返回数据(Json格式)封装在data中
[#ftl]
[#include "/_inc/inc.ftl"]
<html>
<head>
<title>打印页面</title>
[#include "/_inc/meta.ftl"]
[#include "/_inc/css.ftl"]
[#include "/_inc/link.ftl"]
</head>
<body onload="getJudgeId()">
<h3>打印进行中</h3>
</body>
<script type="text/javascript">
function getJudgeId()
{
$.get("${ctxPath}/common/waiting/task/usedcar/judge/id",{
},function(data){
if(data.status){
var url="${ctxPath}/common/print/usedcar/judge/" + data.judgeId + "/0";
printPreview(url);
}
});
}
setInterval("getJudgeId()",1000*10);
</script>
</html>
2、SpringMVC controller
@RequestMapping(value = "common/waiting/task/usedcar/judge/id", method = RequestMethod.GET)
public @ResponseBody ModelAndView getShopInJSON() {
FastJsonJsonView view = new FastJsonJsonView();
String judgeId = this.usedCarJudgePrintTaskService.getEarlyTaskJudgeIdByStatus("0");
Boolean status = false;
if(judgeId!=null&&judgeId.length()!=0){
status = true;
view.addStaticAttribute("status", status);
view.addStaticAttribute("judgeId", judgeId);
}else{
view.addStaticAttribute("status", status);
}
return new ModelAndView(view);
}