I'm currently making a project which requires ajax calls and I have made a function which triggers the AJAX in a single line. The callback functions are defined inside the $(document).ready() scope. I tried defining the scope in the start of $(document).ready() but I still get undefined from typeof fn
.
$(document).ready(function() {
let scope = this;
function test(recvData) {
alert("IT WORKS!")
}
function triggerAjaxDirectInterface(data, async, callback, extra_input) {
console.log(callback)
$.ajax({
data: {
command: data,
scoutId: ScoutGlobals.bridgedId
},
type: 'POST',
async: async,
url: '/direct_process',
success: function(recvData) {
if (typeof callback !== "string") {
if (extra_input !== undefined) {
callback(recvData, extra_input);
} else {
callback(recvData);
}
} else {
if (extra_input !== undefined) {
let fn = scope["test"];
console.log(typeof fn
if (typeof fn === "function")
fn(recvData, extra_input);
}
else {
let fn = scope["test"];
console.log(typeof fn)
if (typeof fn === "function")
fn(recvData);
}
}
}
}
});
}
});