java 靜態頁面 ajax交互

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("數據獲取失敗");
					}
                });
相關文章
相關標籤/搜索