/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Newbie – Looping not working

The below code is printing certain values from every row in a CSV that i’m pulling from the server. As you can see in the processLoop function, I am trying to have it delay 3 seconds before displaying the next bit of data. The loop should go on forever. Displaying the contents every 3 seconds.

What it is doing is just quickly displaying everything and the last line in the CSV is what is always showing. If i place an alert before the document.GetElementById line, it will alert me and show the all the data after every alert. So it is looping.. just want it to stop and wait 3 seconds before showing the next bit of data. Please help.

I posted this in JavaScript forum, thinking its not related to jQuery.. but was redirected here. so sorry for double post.

[CODE]<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″/>
<title>scratch test</title>
<script src=jquery-1.8.2.js></script>
<script src=jquery.csv.js></script>
<script type=”text/javascript”>
var csvData;
$(document).ready(function() {
csvData = $.ajax({
type: “GET”,
url: “http://localhost/test.csv”,
dataType: “text”,
success: function (result) {
csvResult = result;
processCsvData(csvResult);
}
});
});
function processCsvData(csvResult) {
var data = $.csv.toArrays(csvResult);
for(var row in data) {
for(var item in data[row]) {
processLoop(data);
}
}
}
function processLoop(data) {
setInterval(function(){
var lR;
for (lR = 0; lR < data.length; lR++){
document.getElementById(“test1”).innerHTML = data[lR][0];
document.getElementById(“test2”).innerHTML = data[lR][2];
document.getElementById(“test3”).innerHTML = data[lR][4];
document.getElementById(“test4”).innerHTML = data[lR][5];
}
},3000);
}

</script>
</head>
<body><center>
<p id=test1></p>
<p id=test2></p>
<p id=test3></p>
<p id=test4></p>
</center>
</body>
</html>[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @substancev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...