java代码 javascript
public String getAllForum(){ List<AppForumEntity> forumEntity=forumService.getAllAppForum(); /* AppForumEntity json1=forumEntity.get(0); String json= JSON.toJSONString(json1);*/ String json= JSONArray.toJSONString(forumEntity); System.out.println(json); return "flightHandler("+json+")";//跨域请求 }
HTML页面html
$.ajax({ url:"http://localhost:8080/app/forumApp/getAllForum", async:false, type:"get", dataType: "jsonp",//必须 jsonp: "callback",//必须 jsonpCallback:"flightHandler",//必须 success:function(result){ for(var i=0;i<result.length;i++){ $("#content").html(" <div class='div_column'> <img src='"+result[i].imgUrl+"' alt=' / class='img_width'><p class='content_title' >标题</p><p class='content_active'>111人学过</p></div>"); } }, error:function(result){ alert("数据获取失败"); } });