Link Cancel Request

35 views
Skip to first unread message

Sid-ahmed D

unread,
Feb 8, 2012, 10:47:02 AM2/8/12
to mootool...@googlegroups.com
Hello world,

I need your help, please ^^

3 requests are started by function "form_comment(x)" but just one can running.
I try to use link cancel but doesn't work.

"div" name is a primordial element and it can change depending on page.

form_comment(div1);
form_comment(div1);
form_comment(div1);

form_comment = function(id){
    new Request.JSON({
                url: '/echo',
        data: $(id),
        link: 'cancel',
               onRequest: function() {},
               onComplete: function (json) {}   
            }
        }).send();
};

Could you please help me ?

Dimitar Christoff

unread,
Feb 8, 2012, 10:50:47 AM2/8/12
to mootool...@googlegroups.com

it is because you create a new instance every time. to make this work,
you need to have a common variable reference to your request instance
that you reuse.

like:

var request = new Request({ link: 'cancel' ... });

request.send();
request.send();
request.send();

... will likely only result in the last one completing.

regards,
--
Dimitar Christoff

"JavaScript is to JAVA what hamster is to ham"
Personal blog: http://fragged.org/ - Twitter: @D_mitar

Sid-ahmed D

unread,
Feb 8, 2012, 10:54:36 AM2/8/12
to mootool...@googlegroups.com
Arrf
But i lost a parameter "div" ?

Dimitar Christoff

unread,
Feb 8, 2012, 10:55:14 AM2/8/12
to mootool...@googlegroups.com
here's an example pattern for your function:

(function() {

var request = new Request.JSON({
url: '/echo',


link: 'cancel',
onRequest: function() {},
onComplete: function (json) {}
}

});

this.form_comment = function(id){
request.send(document.id(id));
}
})();


form_comment(div1);
form_comment(div1);
form_comment(div1);

... or

request.setOptions({
data: document.id(id)
});

etc - you get the idea.

Sid-ahmed D

unread,
Feb 8, 2012, 11:04:17 AM2/8/12
to mootool...@googlegroups.com
almost perfect ... but I need div name in onComplete for example.

onComplete: function (json) {}
      $('form_'+id).dispose();        
}

Have you an idea ?

Dimitar Christoff

unread,
Feb 8, 2012, 11:10:54 AM2/8/12
to mootool...@googlegroups.com

sure. just store a private id that changes on calling the function and
reference that in a selector in the onComplete

(function() {

var disposeid, request = new Request.JSON({


url: '/echo',
link: 'cancel',
onRequest: function() {},
onComplete: function (json) {}

var form = document.id("form_" + disposeid);
form && form.dispose();
}
});

this.form_comment = function(id){
disposeid = id;
request.send(id);
}

})();

Sid-ahmed D

unread,
Feb 8, 2012, 11:15:25 AM2/8/12
to mootool...@googlegroups.com
Wa awesome.
It's perfect thank you very much for your help.
Message has been deleted

Sid-ahmed D

unread,
Feb 24, 2012, 9:55:49 AM2/24/12
to mootool...@googlegroups.com
Hello Everyone,
It's me again for same issue with addEvents

My example : http://jsfiddle.net/RLvAa/
If i execute this, it's working.

If i remove one "request.send();"
and i write in #locate and if request during 2 seconds for example, it's not working.

Requests launch one after others.

Matthew Hazlett

unread,
Feb 24, 2012, 10:00:55 AM2/24/12
to mootool...@googlegroups.com
http://jsfiddle.net/hazlema/RLvAa/1/

made a little change but is working with multiple requests in chrome.

Sid-ahmed D

unread,
Feb 24, 2012, 1:24:45 PM2/24/12
to mootool...@googlegroups.com
Not working for me.

On Firefox or chrome.

Sid-ahmed D

unread,
Feb 26, 2012, 8:13:42 AM2/26/12
to mootool...@googlegroups.com
Someone can help me?

Arian Stolwijk

unread,
Feb 26, 2012, 12:37:03 PM2/26/12
to mootool...@googlegroups.com
I guess you're looking for this: http://jsfiddle.net/RLvAa/2/

Sid-ahmed D

unread,
Feb 27, 2012, 10:32:48 AM2/27/12
to mootool...@googlegroups.com
Awesome.
Thank you very much ^^

Reply all
Reply to author
Forward
0 new messages