wanted to check a value through ajax for validation purpose. my function getting respose true
or false
. but cannot return reponse to function callback_validation
.
when i call below function its returning undefined.
console.log(callback_validation('value',<object>)); /* here its returning undefined */
Above function supposed to return me TRUE or FALSE.
find my action javascript function here:
function callback_validation($val,$field){
var $jObj=[],$data={
ci: $ci,
ui: $ui
};
$data[$field.attr('name')]=$val;
$jObj.push($data);
console.log(JSON.stringify($jObj)); /* CONSOLE OUTPUT: [{"ci":"","ui":"4934","refno":"s"}] */
$.ajax({
url: $url,
type: 'post',
dataType: 'json',
success: function (res) {
/* console.log(res.valid); */ /* here its returning true / false */
return res.valid;
},
data: $data,
error: function(xhr, desc, err) {
console.log(xhr);
console.log('Details: ' + desc + '\nError:' + err + '\n');
return false;
},
cache: false
});
}