简体   繁体   中英

ajax load different page div into a div

i am trying to load a div from another page into a div

the issue is that the other page div is loaded via js as well

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

is there any way to make the page fully loaded then get the 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

I have a question. Is '#here' div inside https://mywebsite.com/pageiwantoload request? In this case you aren't loading html just parsing it. Always use $(document).ready to wait for a full-loaded page. If you have dependencies between AJAX calls use $.done instead of callbacks.

for example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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