In my event handler function I need to check if some field is unique. To achieve this I use ajax call to the function in back end.
From that function data is send back using callback. at this moment I have Event handler:
self.searchKeyboardCmd = function (data, event) {
if (event.keyCode == 13) {
foo(function (callback) {
if(!callback){
return false // Returning only from this method. Not parent method
}
});
var a = new Eq();
a.StorageId(self.StorageTemp());
a.StartDate(self.StartDateTemp());
a.DeviceSerialNumber(self.Test());
a.DeviceId(self.DeviceTemp());
a.Issue(self.Issue())
a.IssueDesc(self.IssueDesc());
a.Quantity(self.number());
a.Project(self.Project());
a.MeUser(self.MeUser());
self.data.push(a);
$('.datepicker').datepicker({ autoclose: true, todayHighlight: true/*, language: "pl"*/, format: 'dd/mm/yyyy' });
self.Test("");
return false;
}
return true;
};
In which in lines:
foo(function (callback) {
alert(callback);
});
I call this method with ajax call:
function foo(callback) {
$.ajax({
url: "/DeviceInstance/IsUnique",
contentType: "application/json; charset=utf-8",
type: "POST",
datatype: "json",
data: JSON.stringify({ value: viewModel.Test() }),
error: function (data) {
alert("Dodanie nie powiodło się " + data);
},
success: function (data) {
callback(data);
}
});
}
At this moment correct data is received by foo
in main method. But I need to make searchKeyboardCmd
aware of the value of the callback value from Ajax call. I read in my other question that I need to make searchKeyboardCmd
accepting callback from foo
call.
Please do net send me to the question How do I return the response from an asynchronous call?. I'm reading that topic all day and still got nothing