関数を使用して呼び出し$.post
内にを埋め込もうとしていますが、データがコールバック関数に送信されるときに次のエラーが発生します。$.ajax
setTimeout
TypeError:data.sectorは未定義
です(var i = 0、len = data.sector.length; i <len; i ++){
どんな助けでも解決は大歓迎です。
ajaxのもの:
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);
}
}