This is frustrating as hell. I'm getting a jsonp result cross domain that I can see coming across the wire.
my ajax function is
function loadPropertylatlon(propertyid) {
var mydata;
$.ajax({
crossDomain: true,
url: "/MapData.asmx/GetLatLonp",
type: "POST",
data: { id : propertyid },
//async: false,
cache: true,
contentType: "application/json;",
dataType: "jsonp",
success: function (data, textStatus, jqXHR) { //
mydata = data;
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
console.log(xmlHttpRequest.responseText);
console.log(textStatus);
console.log(errorThrown);
alert("Screen shot this error GetLatLon: " + jqXHR.toString() + " " + textStatus.toString() + " " + errorThrown.toString());
}
});
return mydata;
}
// Load data from ajax
latlondata = loadPropertylatlon(GetQueryStringParams('id'));
if I stringify data from the call I get this.
[{"lat":"25.555555","lon":"-80.555555","address":"1 main st, MIAMI, FL 33130","id":0,"count":0,"state":null}]
The problem I'm having is that if I attempt to access latlondata[0].lat I get nothing.
If I $.each the data in the ajax call like this
$.each(data, function (i, value) {
console.log('Value of ' + i + ' is : ' + value);
$.each(value, function (ii, vvalue) {
console.log('obj Value of ' + ii + ' is : ' + vvalue);
})
})
I get an output of
Value of 0 is : [object Object]
obj Value of lat is : 25.854073
obj Value of lon is : -80.174575
obj Value of address is : 1105 ne 85th st, MIAMI, FL 33138
obj Value of id is : 0
obj Value of count is : 0
obj Value of state is : null
The issue is the data is not returning properly outside my function.
If I try to stringify this I get an undefined.
// Load data from ajax
latlondata = loadPropertylatlon(GetQueryStringParams('id'));
// latlondata is undefined.. why?
alert(JSON.stringify(latlondata));