0

Hi I have a problem with this. I'm loading a new page into my DOM, in a container, and the alert is displayed before the elements like images or videos are loaded.

height : function (){ 
    var newHeight = $('#primary').height();   
    var el = $('.show-container');
    el.css({'height': newHeight + 'px'});    
},

loading : function(page){           
    var self= this;
    $.ajaxSetup({cache:false}); 
    $('#ajax-inserted1').load(page, function(){   
         $('#remove').removeClass('to-screen').addClass('to-left');
         $(this).removeClass('to-right, to-left');
         $(this).addClass('to-screen');

         self.height();
     });
 },

Is it possible to wait until everything has fully loaded?

Pablo Levin
  • 217
  • 1
  • 10
  • possible duplicate of [How to return the response from an Ajax call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) – Rafael Feb 01 '15 at 03:04

1 Answers1

0

Yes you can use $.get(url, data, success) which is nearly the same except that it is a method rather than global function and it has an implicit callback function.

Then set the ASYNC property to false.

This is not recommended since AJAX was made for async calls. But that is one way to do it.

It is best to use the complete callback that is in the third parameter of .load() to do anything after the AJAX call.

.load( url [, data ] [, complete ] )

Ex

$('#ajax-container').load(page, function(){   
    var height = $(this).height();
    alert(height);
});
Rafael
  • 7,605
  • 13
  • 31
  • 46