Forum Moderators: open
function getPostcodes(north, south, west, east)
{
postcodes = $.getJSON('/properties/search/get-postcodes-in-area/north/'+north+'/south/'+south+'/west/'+west+'/east/'+east, function(data)
{
postcodes = data;
//console.log(postcodes);
return postcodes;
});
console.log(postcodes);
return postcodes;
}
postcodes = $.getJSON(...);
// Asynchronous request send to the server, but no response yet
// postcodes equals nothing useful
console.log(postcodes);
// postcodes still equals nothing useful
return postcodes;
// postcodes still equals nothing useful
// Response comes back from server and anonymous callback function executes
$('#find').click(function(){
bounds = google.maps.Polygon.prototype.getBounds();
north = bounds.getNorthEast().lng();
south = bounds.getSouthWest().lng();
west = bounds.getSouthWest().lat();
east = bounds.getNorthEast().lat();
//console.log(north);
//console.log(south);
//console.log(west);
//console.log(east);
$.getJSON('/properties/search/get-postcodes-in-area/north/'+north+'/south/'+south+'/west/'+west+'/east/'+east, function(data){
if(!data)
{
north = north + 0.00002;
south = south - 0.00002;
west = west - 0.00002;
east = east + 0.00002;
//need to run get json again!
}
});
});
$('#find').click(function(){
bounds = google.maps.Polygon.prototype.getBounds();
north = bounds.getNorthEast().lng();
south = bounds.getSouthWest().lng();
west = bounds.getSouthWest().lat();
east = bounds.getNorthEast().lat();
//console.log(north);
//console.log(south);
//console.log(west);
//console.log(east);
function getPostCodes(data){
if(!data) {
north = north + 0.00002;
south = south - 0.00002;
west = west - 0.00002;
east = east + 0.00002;
//need to run get json again!
$.getJSON('/properties/search/get-postcodes-in-area/north/'+north+'/south/'+south+'/west/'+west+'/east/'+east, getPostCodes);
return;
}
// If you make it here, you've got your result!
}
$.getJSON('/properties/search/get-postcodes-in-area/north/'+north+'/south/'+south+'/west/'+west+'/east/'+east, getPostCodes);
});