텍스트 파일을 반복해서 읽고 텍스트를 기반으로 페이지를 변경하려고합니다. 현재 파일을 읽는 방식이 오래 걸리며 빠른 방법이 있는지 묻습니다.jquery 빨리 파일을 읽을
<script>
scoreIsShown = false
team1 = ""
team2 = ""
score1 = 0
score2 = 0
function UrlExists(url)
{
$.get("showscore.txt", function(data) {
$(".result").html(data);
showscore = (data.toLowerCase() == "true")
});
$.get("team1.txt", function(data) {
`enter code here`$(".result").html(data);
//(data);
team1 = data
});
$.get("team2.txt", function(data) {
$(".result").html(data);
//(data);
team2 = data
});
$.get("score1.txt", function(data) {
$(".result").html(data);
//(data);
s = (data.toLowerCase() == "true")
score2 = parseInt(data)
});
$.get("score2.txt", function(data) {
$(".result").html(data);
//(data);
score2 = parseInt(data)
});
}
function showScore1()
{
x = document.createElement("table")
tr = document.createElement("tr")
td = document.createElement("td")
team1p = document.createTextNode(team1)
td.appendChild(team1p)
tr.appendChild(td)
x.appendChild(tr)
document.body.appendChild(x)
}
function onload()
{
while (true){
UrlExists("binary1.txt")
setTimeout(function()
{
if (showscore)
{
if (!scoreIsShown)
{
showScore1()
}
}else{
if (scoreIsShown)
{
//hideScore()
}
}
}, 10)
}
}
</script>
모든 파일은 한 줄로 길이가 10 문자 미만입니다.
정말로 질문에 답할 수는 없지만 파일을 json으로 변환 할 수없고 json 데이터를 가져 오기 위해 ajax 요청을 사용할 수없는 이유가 있습니까? – Michael
또한 실제로 귀하의 질문에 대답하지 않지만 거기에 이상한 데이터 형식 으로이 일을 콘솔에 오류가 없습니다 - 아마도 $ .get ('showscore.txt', function (data) {...}, 'text'); – dmoo
참고 사항 : score1은 점수 2의 결과를 저장합니다. :) @Michael처럼 간단한 JSON에 데이터를 저장하고 읽는 것이 더 좋을 것입니다. 그러나 그렇더라도 왜 5 개의 텍스트 파일을 읽는 데 오랜 시간이 걸리는지, 300 보 모뎀을 통해 웹 사이트를 실행하는지 알 수 없습니다. :) – Keith