Thirupathi
Thirupathi

Reputation: 81

$('document').ready() function not working after ajax response

Ready function not working after ajax response.Below is my code.

function AjaxLoaded() {
 $.ajax({
  type: 'POST',
  url: 'abc.php', 
  data: dataString, 
  success: function(result) {
  $('document').trigger('ready');
 }
});
}

But this is not working at all.Any answers will be appreciated.

Upvotes: 0

Views: 4288

Answers (2)

Cerlin
Cerlin

Reputation: 6722

it should be

$(document).trigger('ready');

not

$('document').trigger('ready');

Still this wont work as jQuery releases all the handlers assigned to ready event once its been executed.

Edit

You can assign like

$(document).on('ready urmethod',function(){})

And call like

$(document).trigger('urmethod');

Upvotes: 5

Rory McCrossan
Rory McCrossan

Reputation: 337560

Firstly it should be $(document), not $('document'), however that is moot as you cannot manually trigger the ready event on the document. It only fires once on page load.

If you have some code you want to run after this AJAX call completes put it in a function and call that instead.

You could use $.holdReady() however I would suggest not interfering with the firing of base DOM events.

Upvotes: 3

Related Questions