setTimeout 함수를 사용하여 $ .ajax 호출 내에 $ .post를 포함하려고하는데 콜백 함수에 데이터가 전송 될 때 다음 오류가 발생합니다.
오류 : data.sector가 을 위해 정의되지 않는다 (VAR I = 0, = LEN data.sector.length 내가 < LEN을, 난 ++) {를
어떤 도움 해상도가 크게 이해된다.
아약스 물건 :
var browserUTC = new Date().getTime();
var test = Math.floor(browserUTC/1000);
//document.write(test);
$.ajax({
type : 'POST',
url : 'php_scripts/currentFile.php',
dataType : 'json',
data : { "func" : "getFirstAndNext", epochTime : browserUTC, "func" : "getUpdateAndInterval" },
success : function(data) {
data1 = JSON.parse(data.first);
next = JSON.parse(data.next);
sector_callback(data1);
console.log(data.interval);
console.log(data.update);
setTimeout(function() {
// ajax to retreive new file
$.post ('php_scripts/newFile.php',
{
epochTime : data.next,
dataType : 'json',
data : { "func" : "getNext", epochTime : data.next },
}),
removeSectors();
next = JSON.parse(data.next);
console.log('hello');
console.log(next);
sector_callback(next);
//console.log('worked');
console.log("Ding!",Date()); // This is where I will load first JSON file
setInterval(function() { console.log("Dong!",Date()); }, data.interval * 60 * 1000);
}, data.update);
},
error : function (XMLHttpRequest, textStatus, errorThrown) {
}
});
콜백 :
var allPolygons = [];
function sector_callback(data) {
//console.log(data);
var bounds = new google.maps.LatLngBounds();
for (var i = 0, len = data.sector.length; i < len; i++) {
coords = data.sector[i].geometry.coordinates[0];
siteNames = data.sector[i].properties.Name; // added for site names
health = data.sector[i].properties.Health;
calls = data.sector[i].properties.Calls;
drops = data.sector[i].properties.Drops;
blocks = data.sector[i].properties.Blocks;
TCCFs = data.sector[i].properties.TCCFs;
dcr = data.sector[i].properties.DCR;
TCCFpct = data.sector[i].properties.TCCFpct;
path = [];
for (var j = 0, len2 = coords.length; j < len2; j++){ // pull out each set of coords and create a map object
var pt = new google.maps.LatLng(coords[j][1], coords[j][0])
bounds.extend(pt);
path.push(pt);
}
if (health == 1)
{
var polygons = new google.maps.Polygon({
path: path,
strokeColor: "#000000",
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: "#FF0000",
fillOpacity: 0.35,
map: map
});
} else {
var polygons = new google.maps.Polygon({
path: path,
strokeColor: "#000000",
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: "#000000",
fillOpacity: 0.35,
map: map
});
}
createClickablePoly(polygons, "Site: " + siteNames + "</br>" + "Total_calls " + calls + "</br>" + "Total_drops " + drops
+ "</br>" + "Total_blocks " + blocks + "</br>" + "Total_TCCF " + TCCFs + "</br>" + "DCR " + dcr + "</br>" + "TCCFR " + TCCFpct);
google.maps.event.addListener(polygons, 'mouseover', function() {
var currentPolygon = this;
currentPolygon.setOptions({
fillOpacity: 0.45,
fillColor: "#FF0000"
})
});
if (health == 1)
{
google.maps.event.addListener(polygons, 'mouseout', function() {
var currentPolygon = this;
currentPolygon.setOptions({
fillOpacity: 0.35,
fillColor: "#FF0000"
})
});
} else {
google.maps.event.addListener(polygons, 'mouseout', function() {
var currentPolygon = this;
currentPolygon.setOptions({
fillOpacity: 0.35,
fillColor: "#000000"
})
});
}
allPolygons.push(polygons);
}
}
데이터 : { "func": "getNext", epochTime : data.next}, }), 이 부분이 쉼표로 끝나야합니까? – Zim84