我正在尝试通过ajax从MySql表中获取数据到数据表。它不呈现表格。
HTML :-
<table id="view-site-table" class="table table-striped table-bordered table-hover table-condensed">
<thead>
<tr>
<th>site Id</th>
<th>site Name</th>
<th>user Name</th>
<th>channel Name</th>
</tr>
</thead>
</table>
Ajax :-
var rule_id = $(this).children('td.slNo').text();
$.ajax({
url: '/idns/site/getSitesByRuleId/' + rule_id,
method: 'get',
dataType: 'json',
success: function(data) {
$("#all-rules-summary-table").hide();
$('#view-site-table').show();
$('#view-site-table').DataTable({
data: data,
columns: [{
data: 'siteId'
}, {
data: 'siteName'
}, {
data: 'userName'
}, {
data: 'channelName'
}, ]
});
}
});
Java Resource :-
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/getSitesByRuleId/{ruleId}")
public List<SitesTO> getSitesByRuleId(@PathParam("ruleId") int ruleId) throws ClassNotFoundException, IOException, SQLException{
List<SitesTO>sites=new ArrayList<SitesTO>();
try {
connection =JDBCConnectionUtil.getConnection();
IdnsSiteDAO sitesByRuleId=new IdnsSiteDAO(connection);
sites= sitesByRuleId.getSitesByRuleId(ruleId);
} catch (Exception e) {
logger.error("Error occurs , While trying to getSitesByRuleId.",e);
throw new SQLException("Error occurs , While trying to getSitesByRuleId.");
}
finally{
connection.close();
}
return sites;
}
请帮助我解决此问题。我还想编辑表格行并发送到服务器。