Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-12-18
15
Medium Priority
?
359 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 59

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 59

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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 59

Expert Comment

by:HainKurt
ID: 40507609
0
 
LVL 59

Expert Comment

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

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 59

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 59

Accepted Solution

by:
HainKurt earned 2000 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 59

Expert Comment

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

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

Assisted Solution

by:HainKurt
HainKurt earned 2000 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 84

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

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

705 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