我有一个QTIP工具提示,我正在通过Ajax加载其内容。加载内容后,我需要调用函数somefunction()
$('.element').qtip(
{
content:
{
text: function(event, api)
{
api.elements.content.text('Loading...');
var content = $.ajax(
{
url: 'loadcontent.php',
dataType: 'json'
})
.then(function(result)
{
// Some code for changing result html
return result.html;
}, function(xhr, status, error)
{
api.set('content.text', 'Error');
});
// Calling a function, but it's too early (content is still not in the tooltip)
someFunction();
return content;
}
}
});
说实话,我不确定在哪里放置某个功能(),因此在之后称其为>将内容添加到工具提示中。更改内容后没有触发的事件。
我提出了一个解决方案:
$('.element').qtip(
{
content:
{
text: 'Loading...'
},
events:
{
show: function(event, api)
{
$.ajax(
{
url: 'loadcontent.php',
dataType: 'json'
})
.then(function(result)
{
api.set('content.text', result.html);
someFunction();
}, function(xhr, status, error)
{
api.set('content.text', 'Error');
});
}
}
});