我有一个ajax调用,它将外部网页的div附加到我本地页面上的div。当外部页面的加载页面首先只显示某种微调器或加载栏时,它可以但是,然后它不起作用,因为我的脚本无法找到我想要的div 我的代码中的示例代码段:
loadExtPage('https://www.voltage.com/events/','h2.tribe-events-list-event-title.entry-title.summary, div.author.location','secEvents');
function loadExtPage(url,extEl,intDiv) {
//source: http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/
//loading external content into specific div on page
$.ajax({
url: url,
type: 'GET',
cache: true,
aysnc: false,
success: function(res) {
//attempt to wait for external page to be done loading
$(res.responseText).ready( function () {
var search = $(res.responseText).find(extEl).each(function(){
console.log("Loading to:" + intDiv);
$('#'+intDiv).append($(this).html());
});
if(!search.length) {
$('#'+intDiv).append("<h4>Sorry couldn't load content.</h4>");
}
});
});
<html>
<body>
<div id="secEvents">
<p>External page content goes here.</p>
</div>
</body>
</html>
如果有人知道如何在ajax调用尝试获取内容之前等待外部页面加载,请告诉我们! 在此先感谢您的任何帮助:)