i’m trying to retrieve a lot of addresses using map geoconding.
The problem is that i get “Fatal error: maximum execution time of 300 reached” on my ajax.php page.

So I’d like to handle (reduce) timeout using jquery ajax but it seems that using deferred functions, the option “timeout” is ignored: if I set 3 seconds, the script still run 300 by default.

function initialize() {
var map;
var bounds = new google.maps.LatLngBounds();
var mapOptions = {
    mapTypeId: 'roadmap'
};

map = new google.maps.Map(document.getElementById("mappa"), mapOptions);

var infoWindow = new google.maps.InfoWindow(), marker, i;

// Loop through our array of markers & place each one on the map

loadLocations().done(function (latlngData) {

        for (i = 0; i < latlngData.length; i++) {
            var position = new google.maps.LatLng(latlngData[i].lat, latlngData[i].lng);
            bounds.extend(position);
            marker = new google.maps.Marker({
                position: position,
                map: map,
                title: latlngData[i].nome
            });

        }

    }).fail(function() { //<--------- called after 300 seconds, also if i set timeout on $.ajax to 3 seconds
        $.alert("Error timeout reached");
    });

}



function loadLocations()
{

return $.ajax({
    url : 'ajax.php',
    dataType : 'json',
    timeout: 3 // <---- i've set only 3 seconds to try fail() callback
});

}

google.maps.event.addDomListener(window, 'load', initialize);

1

Khám phá các thẻ bài đăng