ajax發(fā)送請(qǐng)求到controller,controller響應(yīng)一個(gè)json格式的數(shù)據(jù)給頁(yè)面,
JSON.parse()再解析json字符串,用$.each遍歷。
@RequestMapping("/list")
public @ResponseBody java.util.ListUserVO> List() throws Exception{
return service.get();
}
body>
div id="datatable">/div>
/body>
script type="text/javascript">
$(document).ready(function(){
$.ajax({
type:"get",
url:"/meihao/login/list.action",
async:true,
success:function(result){
var m="ul>";
result=JSON.parse(result);
$.each(result, function(i,n) {
console.log(n);
m+="li>"+"姓名:"+n["username"]+"密碼:"+n["password"]+"/li>";
});
m+="/ul>";
$("#datatable").append(m);
},
error:function(error){
alert(error.status+""+error.statusText);
}
});
});
/script>
以上這篇json獲取數(shù)據(jù)庫(kù)的信息在前端頁(yè)面顯示方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:- Ajax獲取數(shù)據(jù)然后顯示在頁(yè)面的實(shí)現(xiàn)方法