Domanda

Ogni mi aiuto. Sto usando il seguente codice per chiamare il servizio web in jQuery Mobile. Ma io sono sempre l'errore "non definito". Si prega di notare me dove ho fatto l'errore. Grazie in anticipo.

Codifica:

$.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);
}
});      

JSON uscita
 [    {       "Tipo": "Profili di affari",       "Title": "Lakeview Restaurant",       "Utente": "Canwest",       "Data": "1280144992",       "nodo":{          "Nid": "67.916",          "type": "business_profiles",          "linguaggio":"",          "Uid": "1",          "Status": "1",          "Creato": "1278994293"       }    } ]

È stato utile?

Soluzione

Stai diventando un indietro array, non un oggetto di base - e anche allora non c'è alcuna proprietà message che posso vedere, quindi dovrebbe essere:

alert(msg[0].title);

In alternativa, ciclo attraverso tutti loro - ad esempio:

$.each(msg, function(i, profile) {
  alert(profile.type);
  alert(profile.node.nid);
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top