Here are the specific API functions I am using to call from JavaScript:
function SuspendActionOp(barcode, owner) {
//alert(barcode+" - "+num);
alert(owner);
if (owner == null) {
alert('owner is null');
} else {
$.ajax({
url: 'http://myserver/myapp/api/Actions?action=2&barcode=' + barcode + '&owner=' + owner,
//data: { id: barcode },
dataType: 'json',
type: 'post',
success: function (a) {
//var t = JSON.parse(a);
if (a.result.localeCompare("suspended") == 0) {
$("#details_" + barcode).modal("hide");
setTimeout(MachinesBigOp(), 2000);
} else {
alert("Error");
}
}
});
}
}
This function is called with a value for owner:
function ActionsOp(stato, barcode, num, owner) {
alert('ActionsOp '+owner);
var btngroup = document.createElement('div');
btngroup.classList.add("btn-group");
switch (stato) {
case 1:
var s = document.createElement("a");
s.onclick = function () {
//var t = owner;
alert(owner);
SuspendActionOp(barcode, num, owner);
};
s.classList.add("btn");
s.classList.add("btn-warning");
s.innerHTML = "❚❚";
btngroup.appendChild(s);
var e = document.createElement("a");
e.classList.add("btn");
e.classList.add("btn-danger");
e.innerHTML = "✔";
e.onclick = function () {
this.parentNode.parentNode.appendChild(ModalEndOp(barcode, owner));
$('#end_' + barcode).modal({ backdrop: false });
};
e.style.marginLeft = "40px";
btngroup.appendChild(e);
break;
case 2:
var a = document.createElement("a");
a.onclick = function () {
this.parentNode.parentNode.appendChild(ModalStartOp(barcode, owner));
$("#start_" + barcode).modal({ backdrop: false });
};
a.classList.add("btn");
a.classList.add("btn-success");
a.innerHTML = "⚡";
btngroup.appendChild(a);
break;
case 4:
break;
}
return btngroup;
}
from:
function ModalDetailsOp(num, owner) {
alert('ModalDetailsOp' + owner);
//.........
var azioni = document.createElement('td');
azioni.appendChild(ActionsOp(a[i].Stato, a[i].Barcode, a[i].NumMachine, owner));
//.........
}
from:
function MachinesBigOp(owner) {
alert('MachinesBigOp'+owner);
$.ajax({
url: 'GetMachines',
data: {},
dataType: 'json',
type: 'get',
success: function (a) {
var cont = document.getElementById("machineContainer");
cont.innerHTML = "";
var l = a.length;
var i = 0;
for (i = 0; i < l; i++) {
var m = document.createElement("a");
m.classList.add('machine');
m.classList.add('hover-shadow');
m.classList.add('show');
m.style.color = "black";
cont.appendChild(ModalDetailsOp(a[i].NumMachine,owner));
//.....
}
and finally from html razor page:
<script>
$(function () {
filterSelection("all");
filterInit();
MachinesBigOp('@Session["id"].ToString()');
});
</script>
When passing the owner variable with its value and calling SuspendActionOp(), the owner value appears to be null. I am struggling to identify the cause of this issue. Any help would be greatly appreciated.