简体   繁体   English

ajax 将不同的页面div加载到一个div中

[英]ajax load different page div into a div

i am trying to load a div from another page into a div我正在尝试将另一个页面中的 div 加载到 div 中

the issue is that the other page div is loaded via js as well问题是另一个页面div也是通过js加载的

this is the code i use这是我使用的代码

$.ajax({
   url: 'https://mywebsite.com/pageiwantoload',
   type: 'GET',
   success: function(res) {
      var data = $.parseHTML(res); 
      $(data).find('#ajap').each(function(){
          $('#here').append($(this).html());
     });
   }
 });

so https://mywebsite.com/pageiwantoload div id ajap is loaded via js as well所以https://mywebsite.com/pageiwantoload div id ajap 也是通过 js 加载的

is there any way to make the page fully loaded then get the div id ajap?有什么方法可以使页面完全加载然后获取 div id ajap? or any other solution或任何其他解决方案

<span class="woocommerce-Price-amount amount" id="ajap">'+c+"</span>

this is what i am trying to get this is inside a js file这就是我想要得到的,这是在一个 js 文件中

I have a question.我有个问题。 Is '#here' div inside https://mywebsite.com/pageiwantoload request? '#here' div 在https://mywebsite.com/pageiwantoload请求中吗? In this case you aren't loading html just parsing it.在这种情况下,您不会加载 html 只是解析它。 Always use $(document).ready to wait for a full-loaded page.始终使用$(document).ready来等待页面加载完毕。 If you have dependencies between AJAX calls use $.done instead of callbacks.如果 AJAX 调用之间存在依赖关系,请使用$.done而不是回调。

for example:例如:

$ajax(urlwholoads#here).done($ajax.pageiwanttolad).done(parserequestandLoad#HereDiv). $ajax(urlwholoads#here).done($ajax.pageiwanttolad).done(parserequestandLoad#HereDiv)。

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

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