Calling a function with callback method
delete_chat_message(messageId,function(result){ if(result.success){ console.log('Chat message is deleted successfully.'); }else{ console.log('Unable to delete Chat message.'); } });
Function Definition with callback execution
delete_chat_message=function(messageId, calbackFunc){ var results = {success: 0, id: messageId} /* Model to delete the chat message*/ AjaxChatMessage.remove({id: messageId}, function(err, data) { console.log('here'); if (err) { results.success = 0; }else{ results.success = 1; } //call the callback function calbackFunc(results); }); }