user1996496 user1996496 - 1 year ago 56
Ajax Question

Why does my JSON data with Ajax not return correctly even though the console logs it?

I am getting a number (1,2,3, etc.) based on coordinates like this:

function getNumber(lat,lng)
var params="lat="+lat+"&long="+lng;
type: "POST",
url: "",
data: params,
dataType: 'json',
success: function(data){
if (data.valid==1){
} else {
error: function(){


The problem is, when I check the console, the data is there like this:

0 Object
lat: 100.00
long: 50.00
number: 1

Why doesn't it let me parse it?

The way I return it with POST is:


Answer Source

So you are returning an array?

Then you need to refer to the data by index:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download