Solved

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

Posted on 2014-12-18
15
297 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 
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 83

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

816 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