I’m using a $.ajax function that serves two purposes and depending on the context, I want to execute different functions on the call-back.
function MyAjaxCall(SomeParameter, CallBackFunctionName) {
$.ajax({
...
success: function (msg) {
var TheData = msg.hasOwnProperty("d") ? msg['d'] : msg;
// here: "execute the function in parameter CallBackFunctionName
// AND pass it the parameter TheData
}
}
How do I write the line where the name of the function is a parameter and I want to pass it TheData as the parameter.
Note, at the moment, I’m writing it like that:
if (CallBackFunctionName === "SomeFunctionName1") {
SomeFunctionName1(TheData);
} else {
SomeFunctionName2(TheData);
}
If the function is defined as a global function then use :
If it isn’t then change the way
MyAjaxCallis called like so:Then inside
MyAjaxCall()do this:Or you could add the object as part of the paramters of
MyAjaxCall():When using it for calling a global function use: