I am passing json obj in the function parameter. Json contains User id, password, success call and error call.
I want to authentic the user via ajax service. if the service returns success the access the successcallback function or returns error then access the errorcallback function.
JSON Obj : Json_Obj = { "UserId" : "uid",
"Password" : "pwd",
"Success_CB" : "successcallback()",
"Failure_CB" : "errorcallback()",
};
I am able to parse the Json_Obj
Authentication = function(data) {
var json_data = $.parseJSON(data);
$.ajax({
type: "GET",
.
.
success:function(data){
json_data.Success_CB; // Unable to Execute the success call back function.
},
error:function(xhr,err){
json_data.Failure_CB
}
});
}
// Call Back Functions
successcallback(){
alert("Success");
}
errorcallback(){
alert("Error");
}
I am unable to access/execute the callback functions.
Please help me out on this..
json_data.Success_CBis a string, not a function.You may do this :
But instead of evaluating any received code, you might prefer to use a switch.
Of course if the function to call isn’t related to the precise data, you may simply do