简体   繁体   English

Ajax调用后未将数据附加到标题标签的操作在第一次悬停时不显示

[英]Data appended to title tag after ajax call is not displaying on first hover

Hi I have a ajax request that will fetch username, email and user_id. 嗨,我有一个ajax请求,它将获取用户名,电子邮件和user_id。 After ajax call success I am appending data using jquery to title tag, main issue I am facing is data getting appended but it is not showing on first attempt, but showing on second time hover. 在ajax调用成功之后,我将使用jquery将数据附加到标题标签,我面临的主要问题是数据被附加,但是第一次尝试时未显示,而是在第二次悬停时显示。

Here is my code 这是我的代码

function showProfile(i)
{
    var user = $("#user_id_"+i).html();
    var business = <?php echo $this->identity()->getBusiness()->getId() ?>;
    $.ajax({
        'url': '/user/account/external/profile',
        'type':'GET',
        'data':{
            businessId:business,
            userId:user,
        },
        'success': function (data) {
            var message = "Fullname : "+data.first_name+" "+data.last_name+" Email : "+data.email;
            $("#user_id_"+i).attr('title',data.first_name+'\n'+data.last_name+'\n' +data.email); 
        },
    });
}

Here is my html code which initiating ajax call 这是我的Ajax调用的html代码

<a id="user_id_btn_'.$k.'" class="user_id_btn" onmouseover="showProfile('.$k.')" onmouseout="hideProfile('.$k.')"><span id="user_id_'.$k.'">'.$iResult[$k][4].'</span></a>

can anybody tell me how to improve this? 谁能告诉我如何改善这一点? I want to show data on hover on first attempt only not second. 我只想显示第二次悬停时的数据。

onmouseover="showProfile('.$k.')" means, that when your mouse moves over this element, the function is called. onmouseover="showProfile('.$k.')"意思是,当鼠标移到该元素上时,将调用该函数。
So if you would make an ajax request when the mouse hovers, the call starts and the data isn't loaded, when the browser processes the tooltip. 因此,如果您在鼠标悬停时发出ajax请求,则当浏览器处理工具提示时,调用将开始并且不加载数据。
On second hover, the data is written from the first call. 在第二次悬停时,数据从第一个调用写入。
Try to set the tooltip before hovering and then you don't need onmouseover because the tooltip is just shown when hovering ;) 尝试在悬停之前设置工具提示,然后就不需要onmouseover了,因为悬停时仅显示工具提示;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM