0

I was wondering what a good way to load an external web page (same server) would be. I have tried .load() and .get() however, The external page has a php script that spits out information every few seconds, the .load() and .get() only load it after the php is done. I have tried iFrame with does load it displaying the information being outputted by the PHP script. However, I don't really like to use iFrames. Thanks!

2
  • Can you show the php script and the ajax call you are currently using? It is difficult to tell what is happening without code. Commented Sep 12, 2013 at 22:54
  • @JoeFrambach, I am not using Ajax. I am using an iFrame. The PHP script doesn't really have anything to do with it. It just has a for loop and spits information every time it goes through. I need that information that's why I am using an iFrame, but I'm wondering if I could display that information with .get() or .load() instead of it just loading after the PHP for loop finishes. Commented Sep 12, 2013 at 22:58

1 Answer 1

1

If your goal is for the PHP information (that is spit out every few seconds) to be updated on your site, then what you want to do is use AJAX, inside a setInterval routine.

See this post for the basics of AJAX -- it really is simpler than you might think. (You might first want to look at the simple examples linked at bottom).

Once you've got a simple ajax exchange happening, put that into a function called, for example, doAjax() -- and then create a setInterval, like this:

setInterval('doAjax();',60000);

Here is an important note when considering setInterval


Following is a simple copy/paste(able) example that will let you see exactly what I mean:

HTML/javascript: index.php

<html>
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        
        <style>
            #timeDiv{width:40%;height:200px;background:wheat;padding:10px;}
        </style>
        
        <script type="text/javascript">
            $(document).ready(function() {

                doAjax();
                
                window.setInterval(function(){
                    doAjax();
                },2000);
                
            }); //END document.ready

            function doAjax() {
                $.ajax({
                    type: "POST",
                    url: "your_php_processor.php",
                    success: function(myData) {
                        $('#thetime').html(myData);
                    }
                });
            }

        </script>
    </head>

<body>

    <div id="timeDiv">
        The time is: <span id="thetime"></span>
    </div>

</body>

</html>

Now, the PHP side... your_php_processor.php

<?php

    $d = date("h:i:s");
    echo $d;
Sign up to request clarification or add additional context in comments.

5 Comments

What post for the Ajax?
My PHP script outputs values and all of those values are needed. However, when I run it again the values start from the beginning, so I can't really do setInterval()
@SiDiX Then (on the PHP side) store the values in SESSION variables and retrieve them each time the PHP script is run. So, each AJAX call, the PHP script simply carries on... read/update/re-save the SESSION vars... echo the updated results.
However, there are like 36 different values that are automatically generated. This is unique for every user.
@SiDiX Probably we (SO helpers) are unable to fully understand the complexities of your task. If you think it worth the time, could you please re-write your question and tell us exactly what you need to do -- and as a group we will put on our thinking caps and come up with a solution for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.