1

I have a rather easy question:

Is it possible to “send” in the code (invisible to the user) a false $(document).ready() in Jquery?

What I want to do is to force all of my Jquery – Code to be ready for action after my Ajax call… I know of the .on() function but it can’t trigger all of my code on the same time other that while loading the main content……

Thank you for your help

ps. I know I didn't post a lot for this question but it still bugs me... pps. Sorry for my english

2
  • So, you want your code to be called once your AJAX call is done? Commented Oct 2, 2013 at 20:26
  • 1
    document ready is just that, it's triggered once, when the document is ready, not after an ajax call. You should learn to use the callbacks provided for the ajax methods. Commented Oct 2, 2013 at 20:26

2 Answers 2

3

A pattern like this could work:

function init() { //do whatever } $(document).ready(init); $.ajax({...}).done(init); 
Sign up to request clarification or add additional context in comments.

9 Comments

Stick an event handler in init, and you have a nightmare !
True, you'd have to be careful about what runs more than once
Interesting concept, but struggling to think of a use case for this (Despite the OP)
I've used a similar pattern with an asp.net UpdatePanel, which basically replaces all the html inside the control when it updates.
so all my code would go in to the init function or the init function triggers all code - right?
|
3

You can do your event handling after ajax complete using .ajaxComplete()

"Whenever an Ajax request completes, jQuery triggers the ajaxComplete event. Any and all handlers that have been registered with the .ajaxComplete() method are executed at this time."

$(document).ajaxComplete(function (event, request, settings) { //event handling }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.