DanielAttard
DanielAttard

Reputation: 3605

Alert an array value that results from an AJAX call

I am having some difficulty trying to alert a value which is the result of an ajax call. The code below is working to the extent that grid.onClick will alert the value of row, but for the life of me I cannot figure out how to alert the value of latitude and/or longitude.

function showGridSalesResult(){
var data = [];
var r_from = $('#min_val').val();
var r_to = $('#max_val').val();
var p_from = $('#from_year').val();
var p_to = $('#to_year').val();
var type = $('#sf3').val();
var municipality = $('#SaleCity').val();

$(document).ready(function(){
jqXHR = $.ajax({
    url: sURL + "search/ajaxSearchResult",
    type: "POST",
    data: 'r_from='+r_from+'&r_to='+r_to+'&p_from='+p_from+'&p_to='+p_to+'&type='+type+'&up_limit='+up_limit+'&low_limit='+low_limit+'&municipality='+municipality,
    dataType: 'json', 
    success: function(json){
        $.each(json, function(i,row){ 
            data[i] = {
                address: row.Address,
                municipality: row.Municipality,
                geoencoded: row.geoencoded,
                latitude: parseFloat(row.geolat),
                longitude: parseFloat(row.geolong)
            };                            
        });

        grid = new Slick.Grid("#myGridMap", data, columns, options);
        grid.invalidate();
        grid.render();
        grid.resizeCanvas();                
        grid.onClick = function (e, row, cell){
            alert(row); // THIS WORKS
            alert(data[row].latitude); // THIS DOES NOT WORK
        }                             
        setMarkers(map, data);
    }    
  });
});
}

Can someone please help me to figure out how I can alert the latitude and longitude values?

Upvotes: 1

Views: 73

Answers (1)

leakim
leakim

Reputation: 34

Checking the documentation : https://github.com/mleibman/SlickGrid/wiki/Slick.Grid#wiki-getCellFromEvent

you should use :

var cell = grid.getCellFromEvent(e);
var latitude = data[cell.row].latitude;
alert(latitude);

Upvotes: 1

Related Questions