jquery No se puede leer la propiedad 'hecho' de indefinido - evite esto
Tengo una función que devuelve resultados (o no). El problema es que cuando no devuelve ningún valor, obtengo en la consola el mensaje
no se puede leer la propiedad 'hecho' de indefinido
Lo cual es cierto y entiendo el problema. Además, este error no hace que mi código deje de funcionar, pero me gustaría saber si hay alguna posibilidad de evitar esto.
La función en ajax es:
function getDelivery(){
var items = new Array();
$("#tab-delivery tr").each(function(){
items.push({"id" : $(this).find('.form-control').attr('id'), "id_option" : $(this).find('.form-control').val()});
});
if(items.length > 0){
return $.ajax({
url: 'response.php?type=getDelivery',
type: 'POST',
data: {content: items}
});
}
}
Y para llamarlo uso:
getDelivery().done(function(data){ // the problem is here
if(data == false){
return;
}
});
Entonces, ¿hay alguna forma de evitar el error? He intentado sin éxito lo siguiente:
if(items.length > 0){
return $.ajax({
url: 'response.php?type=getDelivery',
type: 'POST',
data: {content: items}
});
}else{
return false;
}
Y me sale el error:
TypeError no capturado: undefined no es una función