Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to embed $.post in $.ajax
    primarykey
    data
    text
    <p>I am trying to embed a $.post within a $.ajax call using a setTimeout function but I am getting the following error when data is sent to my callback function:</p> <p>TypeError: data.sector is undefined for (var i = 0, len = data.sector.length; i &lt; len; i++) {</p> <p>Any help is resolution is greatly appreciated.</p> <p>ajax stuff:</p> <pre><code> 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 ) { } }); </code></pre> <p>callback:</p> <pre><code> var allPolygons = []; function sector_callback(data) { //console.log(data); var bounds = new google.maps.LatLngBounds(); for (var i = 0, len = data.sector.length; i &lt; 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 &lt; 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 + "&lt;/br&gt;" + "Total_calls " + calls + "&lt;/br&gt;" + "Total_drops " + drops + "&lt;/br&gt;" + "Total_blocks " + blocks + "&lt;/br&gt;" + "Total_TCCF " + TCCFs + "&lt;/br&gt;" + "DCR " + dcr + "&lt;/br&gt;" + "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); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload