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


i getting number (1,2,3, etc.) based on coordinates this:

function getnumber(lat,lng) {     var params="lat="+lat+"&long="+lng;     $.ajax({             type: "post",         url: "https://www.page.com/code.php",         data: params,         datatype: 'json',                success: function(data){              if (data.valid==1){                                console.log(data);                 $("#number").html(data.number);             } else {                 console.log(data);             }         },          error: function(){                               }               });             } 

the problem is, when check console, data there this:

[object] 0 object lat: 100.00 long: 50.00 number: 1 etc. 

why doesn't let me parse it?

the way return post is:

[{"valid":"1","lat":100.00,"long":50.00,"number":"1"}] 

so returning array?

then need refer data index:

data[0].valid==1 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -