ajax發(fā)送請求到controller,controller響應(yīng)一個json格式的數(shù)據(jù)給頁面,
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ù)庫的信息在前端頁面顯示方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
標(biāo)簽:衡陽 婁底 德陽 黔東 邯鄲 內(nèi)江 樂山 海南
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《json獲取數(shù)據(jù)庫的信息在前端頁面顯示方法》,本文關(guān)鍵詞 json,獲取,數(shù)據(jù)庫,的,信息,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。