带有ajax调用的jQuery ui工具提示无效

带有ajax调用的jQuery ui工具提示无效,jquery,ajax,tooltip,Jquery,Ajax,Tooltip,当前两个用户添加注释时,我在确认按钮上有以下工具提示代码: $("#confirm").tooltip({ content: function(){ $.ajax({ type: 'POST', url: '/comments/numU

当前两个用户添加注释时,我在确认按钮上有以下工具提示代码:

        $("#confirm").tooltip({
                    content: function(){
                                $.ajax({
                                    type: 'POST',
                                    url: '/comments/numUsers.json', 
                                    data: {draw_id : $("#PostId").attr('value')},
                                    dataType: 'json',
                                    success: function(data){

                                        onSuccess(data);

                                     },
                                    error: function(){
                                        return false;
                                    }

                                });

                                function onSuccess(data){
                                    if (data < 2){
                                        if(data == 0){
                                            return "You're the first user";
                                        }
                                        else{
                                            return "You're the second user";
                                        }

                                    }
                                    else{
                                        return false;
                                    }

                                }

                    }
                });
$(“#确认”)。工具提示({
内容:函数(){
$.ajax({
键入:“POST”,
url:“/comments/numUsers.json”,
数据:{draw_id:$(“#PostId”).attr('value')},
数据类型:“json”,
成功:功能(数据){
onSuccess(数据);
},
错误:函数(){
返回false;
}
});
函数onSuccess(数据){
如果(数据<2){
如果(数据==0){
返回“您是第一个用户”;
}
否则{
返回“您是第二个用户”;
}
}
否则{
返回false;
}
}
}
});

json返回已经对帖子发表评论的用户数。ajax调用工作和“onSuccess”函数被正确调用,但我的按钮上没有显示工具提示:-(有什么建议吗?提前thx

您的控制台显示了什么?我认为您不能将函数onSuccess()放在函数Tooltip()中。我尝试console.log(数据)我正确地看到了numUser.json调用返回的用户数。为什么不以相反的方式执行呢?进行ajax调用,并在
success
回调中应用
tooltip
函数。@harikrish我尝试将其放在外部,但不起作用:-(