This is ajax function, I want when data is null
or undefined
than output (#access element
) show me empty "" ( or don't save any data in output when is null or not found )
$(function(){
$('#userId').on('keyup', function () {
var value=$(this).val();
$.ajax('/projectname/admin/getUserAccess/' + value,
{
dataType: 'JSON',
success: function(data){
var str = data.access.replaceAll(/\|/g, ',');
var result = str.substring(1, str.length - 1);
$("#access").val(result);
}
});
});
});
I suggest adding a simple generic function to check emptiness/undefined as this will be handy for other parts of your project too. The Generic function goes like this:-
Thereafter update your success as follows:-
I hope this resolves the hurdle