Guys so I solved the problem of how to load a plugin after an ajax call, but now I am working on how to load a plugin after an ajax call inside another ajax call. The ajax part functions perfectly but the plugin is not loading. Here is the code:
伙计,所以我解决了如何在ajax调用后加载插件的问题,但现在我正在研究如何在另一个ajax调用中的ajax调用之后加载插件。 ajax部分功能完美但插件没有加载。这是代码:
$(document).ready(function () {
var container = $("#content");
var link;
$("a.links").click(function (event) {
event.preventDefault();
link = $(this).attr("href") + " #content";
var link2 = $(this).attr("href");
container.load(link, function () {
if (link2 == 'gallery.html') {
$("a.glinks").click(function (event) {
event.preventDefault();
link2 = $(this).attr("href") + " #content";
$("#content2").load(link2, function () {
var link3 = $("<link>");
link3.attr({
type: 'text/css',
rel: 'stylesheet',
href: 'C:\wamp\www\css\jquery.lightbox-0.5.css'
});
$("head").append(link3);
$('#gallery a').lightBox();
});
});
}
});
});
I also tried to reload the stylesheet again.
我还尝试重新加载样式表。
1 个解决方案
#1
0
Well, you really don't need any of this nesting.
好吧,你真的不需要任何这种嵌套。
Just load the stylesheet from original document. You don't need to load it dynamically:
只需从原始文档加载样式表。您不需要动态加载它:
<link type="text/css" rel="stylesheet" media="all" href="C:\wamp\www\css\jquery.lightbox-0.5.css">
Note: it would be best if the href was a relative path.
注意:如果href是相对路径,那将是最好的。
Now, condense the JS to just one live
click :
现在,将JS压缩为一个实时点击:
$(document).ready(function () {
$("a.links, a.glinks").live('click', function (event) {
event.preventDefault();
var link = $(this).attr("href") + " #content";
var target_div = $(this).hasClass('glinks') ? "#content2" : "#content";
$(target_div).load(link, function () {
$(this).find('#gallery a').lightBox();
});
});
});
#1
0
Well, you really don't need any of this nesting.
好吧,你真的不需要任何这种嵌套。
Just load the stylesheet from original document. You don't need to load it dynamically:
只需从原始文档加载样式表。您不需要动态加载它:
<link type="text/css" rel="stylesheet" media="all" href="C:\wamp\www\css\jquery.lightbox-0.5.css">
Note: it would be best if the href was a relative path.
注意:如果href是相对路径,那将是最好的。
Now, condense the JS to just one live
click :
现在,将JS压缩为一个实时点击:
$(document).ready(function () {
$("a.links, a.glinks").live('click', function (event) {
event.preventDefault();
var link = $(this).attr("href") + " #content";
var target_div = $(this).hasClass('glinks') ? "#content2" : "#content";
$(target_div).load(link, function () {
$(this).find('#gallery a').lightBox();
});
});
});