简单模式ajax

Simplemodal ajax

本文关键字:ajax 模式 简单      更新时间:2023-09-26

我有一个函数roadajax(),它将数据附加到.modal内容

$(".modal-content").append("text here");

this.modal内容设置为显示:none;

然后我将OnClick添加到元素中,所以当我单击该元素时,它会在.modal内容上打开一个模态,并在模态上显示它的内容

$(document).on("click", ".element", function() {
    // remove the current active element
    $(".element").removeClass("active-element");
    // add active class on the current element
    $(this).addClass("active-element");
    curitem = $(this).attr("id");
    roadajax(); // assigns content to .modal-content
    // showing the current element modal
    $(".active-element .modal-content").modal();
});

当我点击.element事件处理程序时,我看到了modal!但没有任何数据所以我用firebug检查了一下。。

如果我从事件处理程序中删除了.modal()调用,正常逻辑就会发生,.modal内容由raodajax()填充但是如果我重新添加.modal()调用。。roadajax()似乎无法将数据加载到.modal内容中……某种竞赛条件

我想知道如何将我的数据显示为模态。。还有别的办法吗?

您可以通过放置以下语法来使用直接Ajax模型:

例如

function roadajax() {
     // This is In-built Ajax Functionality Provide by SimpleModel
     $('.modal-content').load('http://yoursite.com/page.html').modal();
}

这将自动在Model中加载您的页面。