-1

On index.html ; an action of the user would trigger a .load() event that load a document generated by php on a div. The loaded document would includes some javascript code. I would want to call the javascript function that is originally defined on index.html. How can it be done? Simply calling the function on the loaded document wouldn't work.

3
  • Can you post an example? It is difficult to understand what you mean - you're loading into a <div>, but want to call the function defined at window scope? Commented Dec 15, 2012 at 14:42
  • possible duplicate of Jquery .load() is not loading javascript in loaded content Commented Dec 15, 2012 at 14:43
  • code within AJAX loaded page can call the function that is in main document Commented Dec 15, 2012 at 14:46

2 Answers 2

0

call the function you want in the callback argument of the load function

content.load("../includes/fetch.php",{
                'data':url
            },function(){
               whatever_function();
            }
        );

http://api.jquery.com/load/

Sign up to request clarification or add additional context in comments.

Comments

-4

You want all the javascript on the index page, using .on()--which deals with present and future. Meaning you can load something into a div and have it still work. If you try to have the relevant javascript on the dynamically loaded php it won't work.

10 Comments

this is making a big assumption that the function has anything to do with events
-1 last statement about calling code from remote page is simply not true
wow... just pointing out answer is invalid... don't take it so seriously. If you post false information here...expect it to be rebutted as it serves little value
it is still false. Why you insist on dragging this out is beyond me. Your attention could be put to better use clarfiying answer with true statements
grow up and use this site properly
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.