0

I'm developing a tool that generates graphs constantly and uploads it to a web page. What I'm trying to do now is to keep autoloading the graphs after the user selects the graph option. The page is all static with a dynamic div that does all the work. When you choose one option, an Ajax call loads the referenced graph and the only change is on that div.

Something like, if you choose PING, the graph that appear to you is only the PING graph and I want to keep autoloading it in the div.

What suggestions can you give me?

If you have any doubts about how the page is structured, I'll be pleasured to answer.

Shoe
  • 74,840
  • 36
  • 166
  • 272
Minoru
  • 1,680
  • 3
  • 20
  • 44
  • 1
    that's a lot of bandwidth though. Thought about using a JavaScript graphing tool and just sending the data via JSON? – Andrew Grothe Jun 21 '13 at 14:49
  • Can you use `.load()` to place some content into a div, and `setInterval()` to keep doing that every second. – Patrick Beardmore Jun 21 '13 at 15:17
  • I didn't think about it. That's a good idea. Even though, you have any idea on how I can solve the problem? – Minoru Jun 21 '13 at 15:20
  • http://stackoverflow.com/questions/6835835/jquery-simple-polling-example – Rick Suggs Jun 21 '13 at 15:27
  • **Your approach is inefficient.** Why don't you send pure graph data instead of a generated result? This a typical example of bad software conception. – mate64 Jun 21 '13 at 16:05

1 Answers1

0

Thanks for all responses and, especially, for the new idea you gave me about the Javascript Graphing Tool. If anyone ever get the same doubt, here's the solution.

<script>
    $('#button').click(function(){
        buttonContinuousAjaxCall();
    });

    function buttonContinuousAjaxCall(){
        $.ajax({
            url: '<?php echo site_url('controller/method');?>',
            type:'POST',
            success: function(){
            //Do what you need to do
            setTimeout(buttonContinousAjaxCall,5000);
            },
            error: function (x, status, error) {
                alert("Error code: " + x + "\nAn error occurred: " + status + "\nError: " + error);
            }
        });
    };
</script>
Minoru
  • 1,680
  • 3
  • 20
  • 44