The problem is two-fold.
First, once a Modal object is instantiated, it is persistently attached to the element specified by data-target
and subsequent calls to show that modal will only call toggle()
on it, but will not update the values in the options
. So, even though the href
attributes are different on your different links, when the modal is toggled, the value for remote
is not getting updated. For most options, one can get around this by directly editing the object. For instance:
$('#myModal').data('bs.modal').options.remote = "http://website.com/item/7";
However, that won't work in this case, because...
Second, the Modal plugin is designed to load the remote resource in the constructor of the Modal object, which unfortunately means that even if a change is made to the options.remote
, it will never be reloaded.
A simple remedy is to destroy the Modal object before subsequent toggles. One option is to just destroy it after it finishes hiding:
$('body').on('hidden.bs.modal', '.modal', function () {
$(this).removeData('bs.modal');
});
Note: Adjust the selectors as needed. This is the most general.
Or you could try coming up with a more complicated scheme to do something like check whether the link launching the modal is different from the previous one. If it is, destroy; if it isn't, then no need to reload.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…