Pregunta

Cualquier ayuda mí. Estoy utilizando el siguiente código para llamar al servicio web en jQuery Mobile. Pero estoy consiguiendo el error "indefinido". Por favor señalar donde me he hecho el error. Gracias de antemano.

Codificación:

$.ajax({
type: 'POST',
url: "http://jquery.sample.com/nodes.json",
data: ({search_keys :theName}),
dataType: 'json',
timeout: 5000,
success: function(msg) 
{
   console.log(msg);      //here, I can see the result in browser.  
   alert(msg.message);    //Undefined Error
},
error: function(xhr, status, errorThrown) 
{
alert(status + errorThrown);
}
});      

Salida JSON
[ { "Type": "Perfiles de negocios", "Title": "Lakeview restaurante", "Usuario": "Can West", "Fecha": "1280144992", "nodo":{ "NID": "67916", "type": "", business_profiles "idioma":"", "Uid": "1", "Status": "1", "Creado": "1278994293" } } ]

¿Fue útil?

Solución

Te estás poniendo una vuelta matriz, no es un objeto de base - e incluso entonces no hay propiedad message que puedo ver, por lo que debe ser:

alert(msg[0].title);

O, recorrer todos ellos - por ejemplo:

$.each(msg, function(i, profile) {
  alert(profile.type);
  alert(profile.node.nid);
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top