1
I’m making a jQuery.getJSON
at the url http://api.vagalume.com.br/search.php
And should JSON return:
{"type":"notfound"}
or
{"type":"song_notfound","art":{"id":"3ade68b7ga05f0ea3","name":"William Bald\u00e9","url":"http:\/\/www.vagalume.com.br\/william-balde\/"}}
I didn’t want to run some codes, I tried how:
if (data.type != "notfound" || data.type != "song_notfound") {
// Letra da música
$("#letraescrita").html("");
$("#letraescrita").html('<h3>Paroles: </h3><a href=' + data.mus[0].url + ' target=_blank>clique aqui</a><Br>' + data.mus[0].text);
$("#traducao").html("");
$("#traducao").html('<h3>traduction: </h3><Br>' + data.mus[0].translate[0].text);
}
But I think something’s wrong with:
if (data.type != "notfound" || data.type != "song_notfound") {
He’s going into the if
and making a mistake:
Uncaught Typeerror: Cannot read Property '0' of Undefined
in the data.mus[0].text
Use && in place of ||
– Leandro Amorim
Thanks Leandro.... Would you know tell me how in js I do a check to know if date.Mus[0]. Translate[0]. text exists? sometimes this tag doesn’t come in json and then error.
– Dorathoto