jsp页面:
$.ajax({
url:"${ctx}/inkanetportal/login/consulting.action",
data:"",
type:"post",
dataType:"json",
error:function(){
alert("咨询加载失败!");
},
success:function(jsondata){
var len = jsondata.length;
var html="";
for (var i = 0; i < len; i++) {
html +='<li style="list-style-type: none; width: 5px;height: 29px">' +
'<img src="<%=context %>/images/first/arrow_news.gif" hspace="6" align="absmiddle" />'+
'<a href="'+jsondata[i].consultingUrl + '" class="a_art_target"> '+jsondata[i].consultingTitle +'</a>'+
'<span class="news_date">' + jsondata[i].curdate + '</span>' +
'</li>';
}
$("#scorll").html(html);
}
});
$.ajax({
url: 'pubService?service=lData',
type: 'post',
data: {
name:name,
Id:Id
},
success: function(result) {
if(result=="success"){
$.messager.alert('管理信息','保存成功。'); }
}
});
后台:
public void consulting() throws IOException {
String hql="from TConsultingInfo where consultingEndtime >= to_char(sysdate,'yyyy-mm-dd')";
list=loginService.query(hql);
HttpServletResponse respone = ServletActionContext.getResponse();
respone.setContentType("text/html;charset=UTF-8");
PrintWriter out = respone.getWriter();
out.write(JSONArray.fromObject(list).toString());
}
json中放的list 使用:JSONArray.fromObject(list).toString() 或者 JSONSerializer.toJSON(temp3).toString(),返回值为字符串时,直接out.write(String);