function setmclisten(message, sender, sendResponse) {
console.log(data);
if(message['type'] === 'startUp')
{
console.log(data);
sendResponse(data)
}
}
function QuarryToServer(){
chrome.runtime.onMessage.removeListener(setmclisten);
$.ajax({
type: "GET",
async: true,
form: 'formatted',
url: SERVERURL,
success: function (data) {
//sends a get
console.log("set startup listener");
debugger;
chrome.runtime.onMessage.addListener(setmclisten);
},
fail: function () { console.error("error quarrying server"); }
});
}
I am facing an issue where I need the function to have a name so that I can remove the listener later on. However, when I make it a named function, I lose access to the data variable. If I try to pass it like addListen(func(args)), it will just call the function instead of passing it as a variable. Is there a way to pass the variable and still have the function defined in the global scope? To clarify, I have the setmclisten function and I need it to be named while still being able to pass the data argument and receive the onmessage listener arguments like the message itself.