Modify the data format to map which received by web interface

This commit is contained in:
zhixm1988 2014-05-19 09:41:58 +08:00
parent ab06059674
commit 2732b9b3dc
1 changed files with 18 additions and 12 deletions

View File

@ -19,11 +19,15 @@ $(document).ready(function() {
function loadAgents(table) {
table.dataTable().fnClearTable();
$.post("loadAgents", {}, function(data) {
if (data != null) {
if (data.list != null)
for ( var i = 0; i < data.list.length; i++)
addAgentTableRow(table, data.list[i]);
if(data.SUCCESS){
if (data.agents != null) {
for ( var i = 0; i < data.agents.length; i++)
addAgentTableRow(table, data.agents[i]);
}
}
else
alert(data.FAILMESSAGE);
$('.delete').click(function(e) {
e.preventDefault();
deleteAgent(this);
@ -41,33 +45,35 @@ function addAgentTableRow(table, data) {
function deleteAgent(obj) {
var table = getTable(obj);
var row = getRow(obj);
$.post("removeAgentFromPool", {
$.post("deleteAgent", {
id : getColumn(obj, agentColumnIndex.id),
hostName : getColumn(obj, agentColumnIndex.hostName)
}, function(data) {
if (data)
if (data.SUCCESS)
$(table).dataTable().fnDeleteRow(row.rowIndex - 1);
else {
alert("fail");
alert(data.FAILMESSAGE);
}
});
},
"json");
}
function addAgentToDB() {
var table = $('#agents');
$.post("addAgentToPool", {
$.post("addAgent", {
hostName : $("#hostName").val(),
port : $("#port").val(),
maxLoad : $("#maxLoad").val(),
remainLoad : $("#remainLoad").val()
}, function(data) {
if (data) {
if (data.SUCCESS) {
loadAgents(table);
} else {
alert("fail");
alert(data.FAILMESSAGE);
}
});
},
"json");
}
$('#agentList').click(function(e) {
e.preventDefault();