Using Ajax.Request not call function OnSuccess

16 views
Skip to first unread message

yourpadre

unread,
Sep 19, 2008, 3:40:08 PM9/19/08
to Prototype & script.aculo.us
Hi List

I try this
1.- The submit form call mitaller.alta
2.- Popup alert(1)
3.- The data is corrected inserted in database
4.- I expected this.exito run, but not
5.- Popup alert(2)

Why "exito" not run OnSuccess?
If change it to: onSuccess: alert("popup") yes work fine.

var Taller = Class.create({
alta: function (event){
event.stop();
alert(1);
new $('main_form').request({
parameters: $('main_form').serialize(),
onSuccess: this.exito,
onFailure: this.error
});
alert(2);
},

exito: function (transport){
alert(3);
var XML = transport.responseXML.documentElement;
var response = XML.getElementsByTagName('respuesta')
[0].childNodes[0].nodeValue;
if (response == 'bien'){
var accion = XML.getElementsByTagName('accion')
[0].childNodes[0].nodeValue;
if (accion=='alta'){
exito_alta(XML);
}else if(accion=='modificar'){
exito_modificar(XML);
}else if(accion=='eliminar'){
exito_eliminar(XML);
}
}else{
var error_type = XML.getElementsByTagName('error_type')
[0].childNodes[0].nodeValue;
var error_description =
XML.getElementsByTagName('error_description')
[0].childNodes[0].nodeValue;
// var content_error = ;
str = '<strong>Placa:</strong>' + $('bplac').value +
'<br><strong>Error tipo:</strong>' + error_type +
'<br><strong>Descripcion:</strong>' + error_description;
$('estado').update(str);
}
},
})

var mitaller = new Taller();
document.observe('dom:loaded', function(){
$('main_form').observe('submit', mitaller.alta);
});

jason maina

unread,
Sep 19, 2008, 6:43:26 PM9/19/08
to prototype-s...@googlegroups.com
yourpadre,
I stand to be corrected here, but most prototype methods/functions
start with lower case eg onCreate, onFailure etc

Do refer to prototype documentation for actual method/function names.

Regards
jason

--
Sent from Gmail for mobile | mobile.google.com

Miguel Beltran R.

unread,
Sep 22, 2008, 11:14:40 AM9/22/08
to prototype-s...@googlegroups.com
I don't know what do you meant but if I change

onSuccess: this.exito,

to

onSuccess: function (transport){


alert(3);
var XML = transport.responseXML.documentElement;
var response = XML.getElementsByTagName('respuesta')
[0].childNodes[0].nodeValue;
if (response == 'bien'){
var accion = XML.getElementsByTagName('accion')
[0].childNodes[0].nodeValue;
if (accion=='alta'){

this.exito_alta(XML); <---- Here stop, no
call the function
}else if(accion=='modificar'){
this.exito_modificar(XML);
}else if(accion=='eliminar'){
this.exito_eliminar(XML);


}
}else{
var error_type = XML.getElementsByTagName('error_type')
[0].childNodes[0].nodeValue;
var error_description =
XML.getElementsByTagName('error_description')
[0].childNodes[0].nodeValue;
// var content_error = ;
str = '<strong>Placa:</strong>' + $('bplac').value +
'<br><strong>Error tipo:</strong>' + error_type +
'<br><strong>Descripcion:</strong>' + error_description;
$('estado').update(str);
}
},
})


I added to my Class initialize but not work :(
var Taller = Class.create({
initialize: function() {
this.exito.bind(this);
this.exito_alta.bind(this);
},


2008/9/19 jason maina <jason...@gmail.com>:

--
________________________________________
Lo bueno de vivir un dia mas
es saber que nos queda un dia menos de vida

Matt Foster

unread,
Sep 22, 2008, 3:01:54 PM9/22/08
to Prototype & script.aculo.us
Your this scope is lost inside the "this.exito" method. You need to
use a closure, via the bind method to ensure the instance's reference
is maintained in the asynchronous callbacks.

onSuccess : this.exito.bind(this)
> 2008/9/19 jason maina <jason.ma...@gmail.com>:
>
>
>
>
>
> > yourpadre,
> > I stand to be corrected here, but most prototype methods/functions
> > start with lower case eg onCreate, onFailure etc
>
> > Do refer to prototype documentation for actual method/function names.
>
> > Regards
> > jason
>

Miguel Beltran R.

unread,
Sep 22, 2008, 3:24:37 PM9/22/08
to prototype-s...@googlegroups.com
Thanks, It working now :D

2008/9/22 Matt Foster <mattfo...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages