这是 ajax 函数,我希望当数据为null
或undefined
输出时(#access element
)显示为空“”(或者当为空或未找到时不要在输出中保存任何数据)
$(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);
}
});
});
});