Solved

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

Posted on 2014-12-18
15
332 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
15 Comments
 
LVL 56

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 56

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
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

 
LVL 56

Expert Comment

by:HainKurt
ID: 40507609
0
 
LVL 56

Expert Comment

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

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 56

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 56

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 56

Expert Comment

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

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

630 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