[ 3 posts ]

Rakesh.K

  • Username: raksh
  • Joined: Wed Oct 20, 2010 6:08 am
  • Posts: 2
  • GitHub: raksh
  • Gists: raksh
  • IRC: raksh
  • Offline
  • Profile

YUI 3.x IO

Post Posted: Wed Oct 20, 2010 6:32 am
+0-
I am using the IO module to send different POST requests to a servlet.
Function code is given below. The 'execute' function is used my different part of the application to contact servlet.
The issue i am facing here is regarding the 'success' function getting called repeatedly. for example, if the 'execute' function is called for the 3rd time, the success function will be called 3 times; and so the 3 different 'responsefunc' will be executed (The one corresponding to the latest request and the previous two) !!.
Is it a YUI bug, configuration issue, or my mistake in coding? :?
Please help.

this.execute = function(callback) {
var cfg = {
method: "POST",
data: this.getRequest(),
sync: this.sync,
headers: { 'X-Transaction': 'POST Example'}
};

var success = function (x, o){
try {
responseFunc(o.responseXML, callback);
}catch(e)
{
alert("Parsing response failed!");
return;
}
}
var failure = function (x, o){
alert("io failed !");
}
Y.on('io:success', success);
Y.on('io:failure', failure);

var request = Y.io("/Test/TestServlet", cfg);
}

Thomas S. Sha

YUI Contributor

  • Username: tsha
  • Joined: Thu Jan 08, 2009 10:16 am
  • Posts: 206
  • Offline
  • Profile
Tags:

Re: YUI 3.x IO

Post Posted: Wed Oct 20, 2010 10:56 am
+0-
Move the event subscription code out of this.execute. Each call to this.execute adds new listeners for the io events.

Otherwise, move the listeners into the configuration object. For example:
{
method: 'POST',
data: this.getRequest(),
on: { success: function() {}, failure: function() {} }
}

(Your usage of configuration.sync is incorrect. It should be a boolean, set to true if you want io to issue a synchronous request.)

Regards,
Thomas

Rakesh.K

  • Username: raksh
  • Joined: Wed Oct 20, 2010 6:08 am
  • Posts: 2
  • GitHub: raksh
  • Gists: raksh
  • IRC: raksh
  • Offline
  • Profile
Tags:

Re: YUI 3.x IO

Post Posted: Thu Oct 21, 2010 4:23 am
+0-
Thanks a lot Thomas. It works.
Had tried detaching the event listener each time to avoid this issue. But now it is perfectly resolved after defining the event handler in configuration.
I have also made sure that the variable assigned to the 'sync' is having a boolean value.

Thanks a lot.
Rakesh
  [ 3 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum