我正在学习Jquery。我有一个普遍的问题,这是我遇到的很多问题。现在,我知道之前已经发布过类似的问题,但没有一个可以直接应用于我的情况。我已阅读jQuery文档,但无法收集明确的答案(但这可能是由于我的新手状态)在同一页面上的多个Ajax调用:从Ajax调用的Ajax调用div
这是它。
让我们说你的网页上有一个div,其他地方有一个按钮。你按下按钮,新的内容加载到div中。
现在让我们说你在那个div中有哪些THEMSELVES链接到ajax调用的按钮。必须做些什么,以确保这些按钮在被第一个Ajax调用重新加载时,都会正确绑定到它们自己的ajax调用。
现在让我具体。
我有一个div,用于保存在我的Q/A网站上提出问题的成员的照片。当我将鼠标悬停在这些照片上时,通过ajax将他们的信息从数据库中提取出来并显示在工具提示上。
但是,在同一页上的其他地方是“按此线程”按钮。如果我按下此按钮,div将重新加载,现在我的照片与div一起以及其余所有内容。但现在工具提示不会工作,直到我刷新。我知道它与绑定(或代表团)有关,但我很难将其解决。
我完全明白这是一个简单的问题 - 但如果有人能解释这一点,我会非常感激。它是一个在我的网站周围出现的问题。
这里是我的两个功能,
我的后续线程函数:
$(document.body).on("click", "#follow", function(){
var followed_id = $('#followed_id').val();
$.ajax({
url: '../ajax/follow_this_member.php',
type: 'post',
data: {
'followed_id': followed_id
},
success: function(html){
$('.stats_member_profile').load('profile_stats.php', {id:followed_id});
$('.follow_and_message').load('follow_and_message_buttons.php', {id:followed_id});
}
});
return false;
});
我的提示功能(qtip插件)
$(function(){
$('img[data]').qtip({
content: {
text: function(event, api) {
$.ajax({
url:'../ajax/tooltip_members.php', // Use data-url attribute for the URL
method: 'post',
data: {
id: $(this).attr('data')
}
})
.then(function(content) {
// Set the tooltip content upon successful retrieval
api.set('content.text', content);
}, function(xhr, status, error) {
// Upon failure... set the tooltip content to the status and error value
api.set('content.text', status + ': ' + error);
});
return 'Loading...'; // Set some initial text
}
},
style: { classes: 'member_summary_box_style' }
});
});
这是一个非常棒的答案。解决了我的问题,但更重要的是我学到了很多东西。通过修改,我可以将其应用于我的网站。非常感谢 – GhostRider 2014-10-17 19:55:38
只需添加....我一直在玩这个整个早上,它的确很棒。作为一个相对的新手(但是积极性很高),用简单的单行代码向正确的方向推动可以在很多领域取得巨大进步.....如果可以的话,我们可以提高x 100。感谢您的帮助 – GhostRider 2014-10-18 09:03:50
@GhostRider,不客气:) – mccannf 2014-10-18 11:33:41