좋아, 흥미로운 문제가 있습니다. 내 페이지는 매번 JSON 요청을합니다. 데이터가 변경되지 않은 경우 아무 것도 할 필요가 없습니다. 문제는 그것이 바뀌 었는지 아닌지를 증명할 수있는 방법을 찾아 낼 수 없다는 것입니다.실행하기 전에 데이터가 새로운 것인지 확인하십시오 (JSON으로 배열 비교)
나는 아무 소용이 같은 시도 : = null이
VAR 스테이션;
상관없이 내가 뭘{
"song": {
"art": "http://cont-sjl-1.pandora.com/images/public/amz/6/2/3/3/886978533326_500W_500H.jpg",
"title": "Hold It Against Me",
"artist": "Britney Spears",
"album": "Femme Fatale Deluxe"
},
"details": {
"playing": "true",
"enabled": "true"
},
"stations": {
"undefined": "False",
"Alex Clare Radio": "False",
"Rap Strength Training Radio": "False",
"Drops Of Jupiter Radio": "False",
"Tween Radio": "False",
"Today's Hits Radio": "True"
}
}
그러나, 여전히 모든 키에 대한 경고를 만드는 JSON을 통과 : 여기
function parseDynamicData(ard) {
//this was something that gave me problems for days
//nice little hack to fix it
if (ard['details']['enabled'] == 'true' && ard['song']['art'] != 'undefined');
{
//turns off the 'server offline' page
if (document.location.toString().indexOf('#offline') != -1)
document.location = '/#tracks';
//update UI
$('#track-title').html(htmlDecode(ard['song']['title']));
$('#track-artist').html(htmlDecode(ard['song']['artist']));
$('#track-album').html(htmlDecode(ard['song']['album']));
$('#track-art').attr('src', htmlDecode(ard['song']['art']));
//set if it's play or pause visible
if (htmlDecode(ard['details']['playing']) == 'true') {
$('#control-pauseplay').html('Pause');
$('#control-pauseplay').attr('href', '/track?proc=2');
} else {
$('#control-pauseplay').html('Play');
$('#control-pauseplay').attr('href', '/track?proc=3');
}
//Now update all of the stations
if (stations == null || stations != ard['stations']) {
$.each(ard['stations'], function (key, value) {
alert(key);
});
stations = ard['stations'];
}
}
}
정상적인 JSON 응답이 모습입니다. 아무도 내가 뭘해야하는지 알지 못하니?
당신의 무관 한 코드 중 일부는 컨텍스트에 도움이 될 것이라고 생각합니다 ... 내 머리 꼭대기에서 두 스테이션 중 하나가 널 (다른 곳에 덮어 쓰여집니다 -하지만 쉽게 잡을 수 있습니다)이거나'! = '비교자가 isn' 당신이 생각하는 것을하는 것. http://stackoverflow.com/questions/3115982/how-to-check-javascript-array-equals 또는 http://stackoverflow.com/questions/1068834/object-comparison-in-javascript –
구조를 게시 할 수 있습니까? 귀하의 자바 스크립트 개체 및 JSON 데이터의? (이 코드에는 배열이 없습니다.) – jbabey
'stations'와 'ard ['stations ']'는 같은 값을 가진 배열이 다른 것 같습니다. – apsillers