如何使用jquery管理多个引导模式。 [英] How to manage multiple bootstrap modals with jquery.
问题描述
所以我有这个功能在我的数据库中设置成就并返回有关在bootstrap 3模态上显示的成就的信息。
So I have this function that sets an achievement in my database and returns infos about the achievement to be displayed on a bootstrap 3 modal.
function setAchievement(idAchievement){
$.ajax({
url: "http://localhost:8080/licenta/setAchievement",
data:{"idAchievement":idAchievement}
}).then(function(data) {
if (data.description != "null"){ // if update was made
$("#description").text(data.description); // set the divs with infos received about the achievement
$("#xp-gained").text(data.xpGained);
}
});
$("#achievementsModal").modal("show"); // display the modal
$( "#continue" ).click(function() { // close the modal when the continue button is clicked
$("#achievementsModal").modal("hide");
});
}
当我只调用一次这样的函数时这个工作正常:
This works just fine when I call the function only once like this:
setAchievement(0);
但有时用户可以做2-3个成就,所以我需要显示2-3个模态(当我关闭一个时,下一个应该打开)。
But sometimes the user can do 2-3 achievements so I need to display 2-3 modals(when i close one, the next one should open).
setAchievement(0);
setAchievement(1);
setAchievement(2);
这是我的问题,即使我的数据库更新了所有3个成就,在视图页面上只有一个模态打开(对于第一个setAchievement(0)调用)。
我看不到这个问题的解决方法。任何提示都会很棒。谢谢。
Here comes my problem, even if my database updates with all 3 achievements , on the view page only one modal opens(for the first setAchievement(0) call).
I can't see a workaround for this problem. Any tips would be great. Thanks.
推荐答案
.ajax({
url: http:// localhost:8080 / licenta / setAchievement,
data:{ idAchievement:idAchievement}
})。then( function (data){
if (data.description!= null){ // 如果更新
.ajax({ url: "http://localhost:8080/licenta/setAchievement", data:{"idAchievement":idAchievement} }).then(function(data) { if (data.description != "null"){ // if update was made
( #description)。text(data.description); // 设置收到有关成就的信息的div
("#description").text(data.description); // set the divs with infos received about the achievement
( #xp-gains)。text(数据.xpGained);
}
});
("#xp-gained").text(data.xpGained); } });
这篇关于如何使用jquery管理多个引导模式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!