MVC5-Call Back function Usage
A callback function is executed once the current action is over.It works asynchronsouly
function LoadDASummaryListUserFields(clFieldsFrom) {
var qs = '?clFieldsFrom=' + clFieldsFrom;
CallWebApiGetPartial('CallList', 'GetPerformaSummaryListFields', CBLoadCLDASummaryListUserUserFields, qs);
}
It is a sample jquery function. Here we are calling a function inside CallWebApiGetPartial
.It takes 4 parameters 1,Our Controller 2,Action 3,CallbackFunction 4,Query String Which may need to be passed
function CallWebApiGetPartial(controller, action, callBack, qryString) {
//alert(serviceData);
//alert(controller + action);
FnShowLoader();
if ((qryString === undefined) || (qryString === null)) {
qryString = '';
}
$.ajax({
url: "/" + controller + "/" + action + qryString,
dataType: "html",
success: function (data) {
FNHideLoader();
callBack(data);
},
error: WebApiPostFailed,
cache: false
});
}
In the above function we are using Jquery ajax to post a value to controller.
The result from controller is received inside 'data' .Which is passed to callBack function
and is returned back to our main js function
function CBLoadCLDASummaryListUserUserFields(htmlScr) {
$('BODY').append(FNGetPopupHtml(htmlScr));
}
Comments
Post a Comment