Reputation: 2344
The code below works fine until the "i" gets to 10.
divCount equals 11.
I added an alert(i);
after the ++i
which confirmed that 10 was reached then nothing happened. Not even updateVer was called.
<script>
var divCount;
var mcsUrl;
var i = 0;
//Count number of Divs
$(document).ready(function(){
divCount = $("div").size();
myLoop(); //update mcs versions
});
function myLoop () {
++i;
mcsUrl = document.getElementById('url'+i).innerHTML;
updateVer(mcsUrl);
}
function updateVer(a) {
$.getScript(a + "/myspeed/MySpeedServer/mss/js", function(){
document.getElementById("version"+i).innerHTML = mss_version;
if (document.getElementById("version"+i).innerHTML != "9.7j") {
document.getElementById("version"+i).style.color = "#FF0000";
}
else {
document.getElementById("version"+i).style.color = "#006633";
}
if (i < divCount) {
myLoop();
}
});
}
</script>
Upvotes: 0
Views: 90
Reputation: 2344
The $.getScript(a + "/myspeed/MySpeedServer/mss/js", function(){
was failing so I needed to add code to compensate for that:
So it now looks like:
$.getScript(a + "/myspeed/MySpeedServer/mss/js")
.done(function() {
document.getElementById("version"+i).innerHTML = mss_version;
if (document.getElementById("version"+i).innerHTML != "9.7j") {
document.getElementById("version"+i).style.color = "#FF0000";
}
else {
document.getElementById("version"+i).style.color = "#006633";
}
if (i < divCount) {
myLoop();
}
})
.fail(function() {
document.getElementById("version"+i).innerHTML = "FAIL";
if (i < divCount) {
myLoop();
}
});
Upvotes: 0
Reputation: 148
arrange your counting...
function myLoop () {
mcsUrl = document.getElementById('url'+i).innerHTML;
updateVer(mcsUrl);
++i;
}
Upvotes: 1
Reputation: 17779
You haven't really provided enough context to solve whatever issue it is that you're having. For instance, what is the contents of a + "/myspeed/MySpeedServer/mss/js"
? That being said, here's a few tips to help debug.
1) Comment out or delete lines of code until it starts working. Maybe start by reducing updateVer
to just:
function updateVer(a) {
$.getScript(a + "/myspeed/MySpeedServer/mss/js", function(){
if (i < divCount) {
myLoop();
}
});
}
2) Check your browser's debug console. See if it is showing any error messages.
3) The success
callback for $.getScript
only runs when the remote script downloads successfully. Are you sure that script #10 isn't giving you something like a 404 error?
Upvotes: 0