Question

Toute une aide-moi. J'utilise le code suivant pour appeler le service Web mobile dans jquery. Mais je reçois l'erreur « non défini ». S'il vous plaît me rappeler où je fait l'erreur. Merci à l'avance.

codage:

$.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 sortie  [    {       "Type": "Profils d'Entreprise",       "Title": "Lakeview Restaurant",       "Utilisateur": "CanWest",       "Date": "1280144992",       "nœud":{          "JNV": "67916",          "type": "business_profiles",          "Langue":"",          "Uid": "1",          "Statut": "1",          "Créé": "1278994293"       }    } ]

Était-ce utile?

La solution

Vous obtenez un retour de tableau, pas un objet de base - et même alors, il n'y a pas de propriété message que je peux voir, il devrait donc être:

alert(msg[0].title);

Ou, boucle à travers tous - par exemple:

$.each(msg, function(i, profile) {
  alert(profile.type);
  alert(profile.node.nid);
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top