Im trying to dynamically update <td> tags based on dynamically assigned ID's. I know my ajax will return a change in powerstate because of the output log. In the console.log it only displays status messages no error and the status messages show as it fires. However even though it will output a specific status message for a vm I'm using as a test and the powerstate will change the image for the powerstate does not change and it remains displaying off.
<script type="text/javascript">
$(document).ready(function() {
$("#submit").click(function() {
$.ajax({
url : "/vmstatus/",
type : "POST",
dataType: "json",
data : {
selected_customer : $("#selected_customer").val(),
csrfmiddlewaretoken: '{{ csrf_token }}'
},
success : function(json) {
setInterval(update, 5000);
var on = '<img src={% static "icons/on2.jpg" %}>'
var off = '<img src={% static "icons/off.jpg" %}>'
console.log('Good');
$('#table_name').append("<table class='sortable table' id='table-repeat-data'><thead><tr><th align='center' data-toggle='tooltip' data-placement='left' title=''> <b>VM Name</b></th><th align='center' data-toggle='tooltip' data-placement='left' title=''><b>PowerState </b> </th><th align='center' data-toggle='tooltip' data-placement='left' title='N'><b>Commands </b></th></tr></thead><tbody>");
for (var index = 0; index < json.vmlist.length; index++) {
if(json.vmlist[index][1] == 'poweredOn'){
$('#table-repeat-data').append ('<tr><td id="' + json.vmlist[index][0] + '">' + json.vmlist[index][0] + '</td><td id="' + json.vmlist[index][1] + '">' + on + '</td><td id="' + json.vmlist[index][2] + '">' + json.vmlist[index][2] + '</td></tr>');
}else{
$('#table-repeat-data').append ('<tr><td id="' + json.vmlist[index][0] + '">' + json.vmlist[index][0] + '</td><td id="' + json.vmlist[index][1] + '">' + off + '</td><td id="' + json.vmlist[index][2] + '">' + json.vmlist[index][2] + '</td></tr>');
}
}
},
error : function(xhr,errmsg,err) {
console.log('Bad');
console.log(xhr.status + ": " + xhr.responseText);
}
});
return false;
});
});
function update(){
$.ajax({
url : "/vmstatus/",
type : "POST",
dataType: "json",
data : {
selected_customer : $("#selected_customer").val(),
csrfmiddlewaretoken: '{{ csrf_token }}'
},
success : function(json) {
var on = '<img src={% static "icons/on2.jpg" %}>'
var off = '<img src={% static "icons/off.jpg" %}>'
console.log('Good');
for (var index = 0; index < json.vmlist.length; index++) {
if(json.vmlist[index][1] == 'poweredOn'){
if(json.vmlist[index][0] == 'ENKI-STR-PDNS1-TEST'){
console.log(json.vmlist[index][1]);
}
document.getElementById(json.vmlist[index][0]).innerHTML = json.vmlist[index][0];
document.getElementById(json.vmlist[index][1]).innerHTML = on;
document.getElementById(json.vmlist[index][2]).innerHTML = json.vmlist[index][2];
}else{
if(json.vmlist[index][0] == 'ENKI-STR-PDNS1-TEST'){
console.log(json.vmlist[index][1]);
}
document.getElementById(json.vmlist[index][0]).innerHTML = json.vmlist[index][0];
document.getElementById(json.vmlist[index][1]).innerHTML = off;
document.getElementById(json.vmlist[index][2]).innerHTML = json.vmlist[index][2];
}
}
console.log( 'update!');
},
error : function(xhr,errmsg,err) {
console.log('Bad');
console.log(xhr.status + ": " + xhr.responseText);
}
});
}
</script>

New Topic/Question
Reply



MultiQuote


|