Solved

How do I get this javascript web page to work? What am I missing?

Posted on 2014-12-18
15
283 Views
Last Modified: 2014-12-18
Can't seem to get the attached webpage to work.

pinger.html
mystyle.css

Created this based upon the code at http://jsfiddle.net/GSSCD/2459/

I added tags and styles and script src, but can't seem to get working. I must be missing something simple.

Thanks for your help.

Rick Lindberg
0
Comment
Question by:Rick_Lindberg
  • 9
  • 5
15 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 40507579
it is working fine (i guess)
i see this:

localhost responded
google.com responded
ws-bdimperio8 timeout
ws-bdimperio8.payformance.net timeout
ws-bdimperio8.payformance.com responded
ws-bdimperio8.payspan.com responded
ws-bdimperio8/favicon.ico timeout
127.0.0.1 responded
unknown timeout

Open in new window

0
 

Author Comment

by:Rick_Lindberg
ID: 40507593
That is what I should see, but when I run it from my desktop. I only get
 
tester

Open in new window

So I must be missing something in how my machine runs javascript.... hmmmm

I am running Foxpro.

Tried opening html file with  IE and then chrome but got the same result.

I am still missing something.
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40507608
knockout-min.js cannot be downloaded or run locally... i may be doing something harmful :) activex permissions missing maybe...
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40507609
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40507610
try saving this file to local, maybe it makes any difference...
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40507613
yup, working fine :)
copy that file to same location with your html, update link and good to go

<script type='text/javascript' src='knockout-min.js'></script>

added to my library for potential future use...
0
 

Author Comment

by:Rick_Lindberg
ID: 40507648
modified the <script> tag line as you suggested
webcode.PNG
with the following files in the directory
Files-in-Development-Directory.png
And I still get this:
NotWorking.PNG
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 51

Expert Comment

by:HainKurt
ID: 40507660
wait a bit (like 30 sec) they will be showing up eventually...
unless you have something wrong in your file (syntax error)
install fiddler and check whats is happening after loading page (check requests)
also press f12 and check for any js errors...

running on ie (local)
0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 40507675
if it helps, here what i have:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Ping a server in javascript - jsFiddle demo</title>
  <script type='text/javascript' src='knockout-min.js'></script>
  <link rel="stylesheet" type="text/css" href="//jsfiddle.net/css/result-light.css">

  <style type='text/css'>
    .responded {
    color:green;
}
.checking, .unchecked {
    color:#FF8C00;
}
.timeout {
    color:red;
}
	</style>

<script type='text/javascript'>//<![CDATA[ 
window.onload=function(){
function ping(ip, callback) {

    if (!this.inUse) {
        this.status = 'unchecked';
        this.inUse = true;
        this.callback = callback;
        this.ip = ip;
        var _that = this;
        this.img = new Image();
        this.img.onload = function () {
            _that.inUse = false;
            _that.callback('responded');

        };
        this.img.onerror = function (e) {
            if (_that.inUse) {
                _that.inUse = false;
                _that.callback('responded', e);
            }

        };
        this.start = new Date().getTime();
        this.img.src = "http://" + ip + "/?now=" + this.start; 
        this.timer = setTimeout(function () {
            if (_that.inUse) {
                _that.inUse = false;
                _that.callback('timeout');
            }
        }, 1500);
    }
}
var PingModel = function (servers) {
    var self = this;
    var myServers = [];
    ko.utils.arrayForEach(servers, function (location) {
        myServers.push({
            name: location,
            status: ko.observable('unchecked')
        });
    });
    self.servers = ko.observableArray(myServers);
    ko.utils.arrayForEach(self.servers(), function (s) {
        s.status('checking');
        new ping(s.name, function (status, e) {
            s.status(status);
        });
    });
};
var komodel = new PingModel(['localhost',
    'google.com',
    'ws-bdimperio8',
    'ws-bdimperio8.payformance.net',
    'ws-bdimperio8.payformance.com',
    'ws-bdimperio8.payspan.com',
    'ws-bdimperio8/favicon.ico',
    '127.0.0.1',
    'unknown']);
ko.applyBindings(komodel);
}//]]>  

</script>

</head>
<body>
  <ul data-bind="foreach:servers">
    <li> <a href="#" data-bind="text:name,attr:{href: 'http://'+name}">tester</a>  <span data-bind="text:status,css:status"></span></li>
</ul>
  
</body>
</html>

Open in new window

0
 

Author Comment

by:Rick_Lindberg
ID: 40507752
did you copy the ping.html from the jsfiddle site. could you post your ping.html file here?

Thanks for all your help,  sorry that I'm not getting there yet.
0
 

Author Comment

by:Rick_Lindberg
ID: 40507783
looks like I was missing the

//<![CDATA[
window.onload=function(){

..... remainder of javascript.....

}//]]>

That did it!!!

Did you copy that script directly from the http://jsfiddle.net/GSSCD/2459/ site?  I couldn't figure out how to do that.
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40507787
yes copied from your jsfiddle :)

using chome, right click, view frame source...
0
 
LVL 51

Assisted Solution

by:HainKurt
HainKurt earned 500 total points
ID: 40507789
I don't think this is issue

//<![CDATA[
//]]>

but a missing "}" is...
0
 

Author Comment

by:Rick_Lindberg
ID: 40507820
Hain thanks for your help

-Rick
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40508055
I tried the original page which didn't work and then HainKurt's version which did work.  I copied different items from HainKurt's back to the original and the modified original started working when I copied the "window.onload=function(){".  I went back and commented it out and I got the original error again so I'm pretty sure that was the issue.  Some things were happening before the page was displayed.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to dynamically set the form action using jQuery.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now