I have a Javascript object which has a jquery ajax call to server to fill one of its attributes:
function Busqueda(contenedor){
var datosPost = "someData";
var resultados = undefined;
var that = this;
this.buscar = function(){
jQuery.ajax({
type: "POST",
dataType: "json",
url: "phpFile.php",
data: datosPost,
success: function (data){
if(data.error != 0){
alert(data.errorTxt);
} else {
that.resultados = data.resultados;
}
}
});
}
}
The ajax call should fill the attribute "resultados". However, after the "buscar" method is run, resultados remains undefined.
Also, I debugged "that.resultados" inside the success method and it is Busqueda's attribute.
What is going on?