As the title says, I'm trying to populate the properties of an object using jQuery-Ajax. I've been trying to find the right way to do it for hours, but couldn't make it work...
This is my code:
function Persona(){
this.nombre;
this.apellido;
this.buscarNombre= function(callback){
$.get("nombre.php", function(datos){
datos = eval("(" + datos + ")");
this.nombre = datos.nombre;
this.apellido = datos.apellido;
alert(this.nombre);
})
};
}
$(document).ready(function(){
var pp = new Persona();
alert(pp.nombre);
}
I think the problem is the scope of the function that retrieves the data from the server it's different from the scope of the object, but I don't realize how to pass the data from one place to the other...
The data is arriving perfectly from the web server... I used FireBug to be sure...
Thanks in advance!
pp.buscarNombre();?