delay execution of javascript function till php page finish executing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shenno
    New Member
    • Sep 2010
    • 59

    #1

    delay execution of javascript function till php page finish executing

    hiz,

    i got a problem that i need javascript function "ajax" to be execute after php page complete executing..

    it's iframe page that uploads an image.. and the javascript function will load latest images...

    i need after iframe php page uploaded the image, then javascript function be called..

    anyone knows how to do this ?

    thx in advance..
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    i got a problem that i need javascript function "ajax" to be execute after php page complete executing..
    no problem. JavaScript (including AJAX) will always execute after PHP. so you might only need to delay the script execution until the website finished loading.

    Comment

    • Shenno
      New Member
      • Sep 2010
      • 59

      #3
      i have 2 php files, 1st is iframe loading, the second contain javascript ajax..

      javascript function on 2nd file called and executed while iframe php page is still loading...

      that's my problem : /

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        you can follow two method,
        1. after getting the text, extract the javascript part and then create a javascript node into main document. WHen you create the node and add the javascript code to the node it will execute the code and create all required function and variable.

        2. you can do it using jquery. Jquery has developed all the way to extract javascript code and execute it in proper manner. here is a simple example how you can achive
        Code:
        $.ajax(
        {
        url: "target.ext", 
        type: 'POST', 
        dataType: 'html', 
        data: "Parameter1=data&Parameter2=data2", 
        timeout: 90000, 
        success: 
        function(retData)
        { 
        $("#MyProcessWindow").html(retData);
        }
        }
        );
        <div id='MyProcessWindow'></div>
        Last edited by johny10151981; Sep 28 '11, 05:03 AM. Reason: Wrong Code

        Comment

        • limweizhong
          New Member
          • Dec 2006
          • 62

          #5
          you can use the event onload on the iframe to run the JavaScript, e.g.
          [CODE=HTML]<script>
          function yourFunction()
          {
          alert("Finished loading!");
          }
          </script>
          <iframe onload="yourFun ction();" src="http://www.google.com" ></iframe>[/CODE]
          Last edited by limweizhong; Oct 5 '11, 01:23 PM. Reason: Formatting

          Comment

          Working...