天天看點

json 擷取mysql資料庫_json擷取資料庫的資訊在前端頁面顯示方法

ajax發送請求到controller,controller響應一個json格式的資料給頁面,

JSON.parse()再解析json字元串,用$.each周遊。

@RequestMapping("/list")

public @ResponseBody java.util.List List() throws Exception{

return service.get();

}

$(document).ready(function(){

$.ajax({

type:"get",

url:"/meihao/login/list.action",

async:true,

success:function(result){

var m="

  • ";

result=JSON.parse(result);

$.each(result, function(i,n) {

console.log(n);

m+="

"+"姓名:"+n["username"]+"密碼:"+n["password"]+"";

});

m+="

";

$("#datatable").append(m);

},

error:function(error){

alert(error.status+""+error.statusText);

}

});

});

以上這篇json擷取資料庫的資訊在前端頁面顯示方法就是小編分享給大家的全部内容了,希望能給大家一個參考,也希望大家多多支援腳本之家。