我有一个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;
}
}
});
说实话,我不知道在哪里放置someFunction(),所以在将内容添加到工具提示后调用它。更改内容后没有触发事件。
我提出了一个解决方案:
$('.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');
});
}
}
});