ajax加载在元素之前插入
我想让 jQuery AJAX 加载按原样在导航之前插入,而不是替换元素的内容。
我试图通过在导航之前将其加载到新的 div 中来实现此目的,但我在展开它时遇到了麻烦,因为 .unwrap()
展开了父级而不是当前的 div。尝试打开 div .children()
会破坏我的 AJAX 负载。
navigation.before(
$('<div />')
.load(nextLink + ' .post', function() {
pageNum++;
nextLink = nextLink.replace(/\/page\/[0-9]?/, '/page/'+ pageNum);
if(pageNum <= max) {
navigation.children('a').text('Load More');
}
else {
navigation.children('a').text('Nothing else to load.');
}
})
);
如果您想知道它来自哪里,它是 使用 AJAX 加载下一个 WordPress 帖子
I want to have the jQuery AJAX load to insert before the navigation as-is instead of replacing the contents of an element.
I'm trying to accomplish this by loading it in a new div before the navigation, but I'm having trouble unwrapping it as .unwrap()
unwraps the parent and not the current div. Trying to unwrap the divs .children()
breaks my AJAX load.
navigation.before(
$('<div />')
.load(nextLink + ' .post', function() {
pageNum++;
nextLink = nextLink.replace(/\/page\/[0-9]?/, '/page/'+ pageNum);
if(pageNum <= max) {
navigation.children('a').text('Load More');
}
else {
navigation.children('a').text('Nothing else to load.');
}
})
);
If you're wondering where this came from, it's a modified version of Load Next WordPress Posts With AJAX
试试这个
Try this