I'm new to Yui but still plan on understanding it. Therefore, I need you ! I'm have a bit of a problem and haven't found any solution yet. Here is the plan :
I have a button and when I click on it, that button will send Json to a webservice. If it was sent successfully, I get a 'success' alert and 'failure' otherwise.
Here is the problem :
So why is that ? Why would it display twice the alert the second time ? Here is the Yui code I am using :
YUI().use('io-base', 'json', 'event', 'querystring-stringify-simple', function (Y) {
Y.one('#connectBut').on('tap', function (e){
var jsonCreateUser = {
"login": "01234",
"password": "TestUser"
},
handleSuccess = function () {
alert("success");
},
handleFailure = function () {
alert("failure");
},
url = 'myServer';
Y.on('io:success', handleSuccess);
Y.on('io:failure', handleFailure);
Y.io(url, {
method: 'POST',
data: jsonCreateUser
});
});
});
IF that sounds any obvious to you, please explain me, really want to understand this one.
Thanks for the help !
Each tap
event on #connectBut
will bind handleSuccess
to io:success
.
You must move the code binding handleSuccess
to io:success
out of the tap
event handler.