简体   繁体   English

Ajax完成后在js中加载iframe或div

[英]Load iframe or div inside js after ajax complete

On my site ajax calling iframe that is loading some sort of data. 在我的网站上,ajax调用iframe正在加载某种数据。 I want to load the iframe or div data as soon as the ajax request completes or data is loaded. 我想在ajax请求完成或数据加载后立即加载iframe或div数据。 I cannot access ajax directly, so I am trying it this way, but it is showing undefined. 我无法直接访问ajax,因此我正在尝试这种方式,但显示未定义。 I think this is due to the iframe or div not loading each time. 我认为这是由于iframe或div每次均未加载。 Any help with how I can load the iframe or div inside js without touching ajax code.Thanks 我如何在不触摸Ajax代码的情况下在js中加载iframe或div的任何帮助。

<script type="text/javascript">
setTimeout(function() { alert(jQuery('#wrapper').html()); }, 10000);
</script>

If I use pplus instead of wrapper its only show empty iframe. 如果我使用pplus而不是包装器,则仅显示空的iframe。 But I want to load its data. 但是我想加载它的数据。 Iframe code looks like this : iframe代码如下所示:

<div id="ppplus" style="height: 535px;"><iframe  allowtransparency="true" style="height: 535px; width: 870px; border: none;">
<html>
<div class="content" id="wrapper">data goes here</div>
</html>

</iframe></div>

i dont know why you want to use i frame just to display data .. use a div. 我不知道为什么要使用i框架只是为了显示数据..使用div。 iframes behave different than divs. iframe的行为与div不同。 you dont have innerHTML. 您没有innerHTML。 you have a body (myFrame.contentDocument.body) 您有一个正文(myFrame.contentDocument.body)

dont use a timer you dont know when the response will be rendered. 不要使用您不知道响应时间的计时器。

add a eventlistener like DOMSubtreeModified or DOMNodeInserted for the wrapper div and get its content 为包装div添加一个事件监听器,例如DOMSubtreeModified或DOMNodeInserted,并获取其内容

  var ppplus = document.getElementById('ppplus');
  ppplus.addEventListener("DOMSubtreeModified",function(e) {
        var myFrame = e.target.firstchild;
        console.log(myFrame.contentDocument.body);
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM