user1996496 user1996496 - 9 months ago 33
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:



So you are returning an array?

Then you need to refer to the data by index: