First time function is return Undefined, every other time it works and return object ....
Basically, the first time that var _d is stored, it is an undefined value.
the first time that it stores its value click is "undefined" and every other time it stores the appropriate value.
// jscript.js
function getDataById(This,table,Url)
{
var Id = table.row(This.parent().parent()).data().id;
$.ajax({
url: Url + "/" + Id,
type: "GET",
dataType: 'json',
success: function (Data) {
var _d = Data;
return _d;
},
error: function () {
sweetAlert("Oops...", "Something went wrong!", "error");
}
});
}
/***********************/
$(document).ready(function () {
$("#test tbody").on('click', '#aff', function () {
console.log( getDataById($(this),table,"test/email") );
});
)};
/*****************/
// undefined