Using Ajax.Request not call function OnSuccess

閲覧: 14 回
最初の未読メッセージにスキップ

yourpadre

未読、
2008/09/19 15:40:082008/09/19
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

未読、
2008/09/19 18:43:262008/09/19
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.

未読、
2008/09/22 11:14:402008/09/22
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

未読、
2008/09/22 15:01:542008/09/22
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.

未読、
2008/09/22 15:24:372008/09/22
To: prototype-s...@googlegroups.com
Thanks, It working now :D

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

全員に返信
投稿者に返信
転送
新着メール 0 件