0

this is my first question in a forum ever i think ;-). I will try to be as clear as possible with the question.

I´m trying to build a visual traceroute similar to that on yougetsignal.com by kirk ouimet.

It is actually working already using bash (traceroute,ping,host,) php/javascript, but I´m having some trouble with Javascript/AJAX.

Kirk updates the traced host-list periodically or via some kind of ajax-interrupt on the right side of the trace. I only know how to do it in one pass with one single Javascript xmlhttp-call and then echo a table into a standard w3school-livesearch-DIV.

http://www.yougetsignal.com/tools/visual-tracert/

I also don´t know if he does the traceroute with a cmd-line-tool like linux´s "traceroute". Mine is working fine by first tracerouting, then doing reverse-lookup using "host" and then pinging all hosts in the list again to get the rrt.

Is there any way to poll a txt-file (the traces) and then echo the output on demand to a DIV?

I´m grateful for any hint.

Stefan

p.s.: the google-maps plotting works fine, it´s about the process of updating the traced-hosts on demand for users (and me) to enjoy.

user2095033
  • 27
  • 1
  • 8
  • Hey, I've pretty much done the same thing. Whole project is here: https://github.com/mnmnc/aquila . I'm using ajax as well to supply the traceroute results to the user so it might be of some help to you. – mnmnc Nov 18 '14 at 16:19

1 Answers1

1

What you can do by using jQuery for ajax calls:

setInterval(function () {
    $('#yourdiv').load('http://domain.com/yourfile');
}, 30000);

This code will load pregenerated html content to a specified div container every 30s. If you don't what to load a temporary generated html/php content, you can build an API and then add the data comming back dynamically on the DOM every time.

setInterval(function () {
    $.getJSON('yourAPIUrl', function (data) {
        $.each(data, function (item) {
            // do something with the retrieved data, add it to the DOM for example
        }
    });
}, 30000);
Pascal Bayer
  • 2,615
  • 8
  • 33
  • 51
  • Thank you! That´s actually looking quite good. I was hoping I could avoid jQuery but it looks like it´s impossible. I´ll give it a try once I get home from work. – user2095033 Feb 21 '13 at 11:51
  • 1
    You can avoid it, that's not a big deal. The code above was only a short demonstration and jQuery is cross-browser compatible but you can also do that by simply using the XMLHttpRequest Object http://www.w3schools.com/xml/xml_http.asp. – Pascal Bayer Feb 21 '13 at 11:56
  • 1
    Here is another example how to implement jQuery getJSON in pure JS: http://stackoverflow.com/questions/10149864/get-json-from-another-php-file-using-pure-javascript – Pascal Bayer Feb 21 '13 at 11:58
  • I just read through http://www.w3schools.com/js/js_timing.asp. This should do it. I will try "polling" the raw-txt-files that traceroute,ping etc generate. I could even build some kind of progress-bar with that. At least I hope so. Thanks again! Incredible response times here ;-) – user2095033 Feb 21 '13 at 12:04