从JSON加载模式内容和Twitter引导。

时间:2021-01-19 19:41:44

Is there a way that I can load a Modal with data from a JSON response?

是否有一种方法可以从JSON响应中加载带有数据的模态?

For example,

例如,

here's a link to sign out of my application:

以下是我的申请签名的链接:

 <a tabindex="-1" href="/ajax/account/logout" data-toggle="modal" data-target="#ajax" class="modal-link">Sign Out</a>

In a normal circumstance, the response will be:

在正常情况下,反应为:

 {"html":"htmlsource",
  "resultCode":1}

The html contains the HTML of the content to be put into the modal, so all I'd need to do is extract the html data and push it to the div container.

html包含要放入模态的内容的html,因此我需要做的就是提取html数据并将其推到div容器中。

2 个解决方案

#1


0  

With this:

用这个:

$.getJSON(url).success(function(data) {
   $('#ajax, div').replaceWith(data.html);
   $('#ajax').modal();
});

#2


1  

Sure; for example, the html() jQuery function will shove its argument into whatever element you wish, including a Modal. In your case, assuming the "html" item has what you want to put in the Modal, you'd do something like $("#id-of-modal").html(response.html).

确定;例如,html() jQuery函数将其参数插入到您想要的任何元素中,包括一个模态。在您的例子中,假设“html”项有您想要放入模式的内容,您将会执行$(“#id-of-modal”).html(response.html)。

#1


0  

With this:

用这个:

$.getJSON(url).success(function(data) {
   $('#ajax, div').replaceWith(data.html);
   $('#ajax').modal();
});

#2


1  

Sure; for example, the html() jQuery function will shove its argument into whatever element you wish, including a Modal. In your case, assuming the "html" item has what you want to put in the Modal, you'd do something like $("#id-of-modal").html(response.html).

确定;例如,html() jQuery函数将其参数插入到您想要的任何元素中,包括一个模态。在您的例子中,假设“html”项有您想要放入模式的内容,您将会执行$(“#id-of-modal”).html(response.html)。