What am I doing wrong?
I am making a ajax request that returns me as callback this type of array or object
[{"nombre":"Kabul"},{"nombre":"Qandahar"},{"nombre":"Herat"},{"nombre":"Mazar-e-Sharif"},{"nombre":"Otra"}]
At the time of reading this array I am doing it in the following way
$.ajax({
type:"POST",
url:url2,
data:{code:code},
datatype:"json",
contenType: "application/json",
}).done(function(response){
var text=response;
var obj=JSON.parse(text);
for (var propiedad in obj) {
if (obj.hasOwnProperty(propiedad)) {
console.log("En la propiedad '" + propiedad + "' hay este valor: " +
obj[propiedad]);
}
}
the ouput
is the next ...
En la propiedad '0' hay este valor: [object Object]
En la propiedad '1' hay este valor: [object Object]
En la propiedad '2' hay este valor: [object Object]
En la propiedad '3' hay este valor: [object Object]
En la propiedad '4' hay este valor: [object Object]
I'm waiting for you to throw me ...
En la propiedad '0' hay este valor: Kabul
En la propiedad '1' hay este valor: Qandahar
En la propiedad '2' hay este valor: Herat
etc...
the php file where this array comes from is this
$data=array();
while($row= $stmt->fetch()){
$data[] = array('nombre'=>$CiudadNombre );
}
echo json_encode($data);
What am I doing wrong I do not understand some friendly hand plis?