PDA

View Full Version : synchroneous Request (syncRequest and asyncRequest functions)



emredagli
7 May 2009, 9:22 PM
Hii,
I used following modification for Synchroneous Request (in Ext2.2),
But it doesn't worked in Ext 3.0.



Ext.lib.Ajax.request = function(method, uri, cb, data, options) {
if (options) {
var hs = options.headers;
if (hs) {
for (var h in hs) {
if (hs.hasOwnProperty(h)) {
this.initHeader(h, hs[h], false);
}
}
}
if (options.xmlData) {
this.initHeader('Content-Type', 'text/xml', false);
method = 'POST';
data = options.xmlData;
} else if (options.jsonData) {
this.initHeader('Content-Type', 'text/javascript', false);
method = 'POST';
data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
}
if (options.async == false) {
return this.syncRequest(method, uri, cb, data);
}
}
return this.asyncRequest(method, uri, cb, data);
};


Ext.lib.Ajax.syncRequest = function(method, uri, callback, postData) {
var o = this.getConnectionObject();

if (!o) {
return null;
}
else {
o.conn.open(method, uri, false);

if (this.useDefaultXhrHeader) {
if (!this.defaultHeaders['X-Requested-With']) {
this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
}
}

if (postData && this.useDefaultHeader) {
this.initHeader('Content-Type', this.defaultPostHeader);
}

if (this.hasDefaultHeaders || this.hasHeaders) {
this.setHeader(o);
}

o.conn.send(postData || null);
this.handleTransactionResponse(o, callback);
return o;
}
};
The error in "this.asyncRequest(...)" row.
I hope it can be modified.

Animal
7 May 2009, 11:45 PM
Why don't you just use an async request? What does your code look like that makes this request?

feiichi
22 May 2009, 12:12 AM
Take this example:

You want to listen to the beforenodedrop event. In this event you can return false to stop dropping the node. Now what if you need to check *something* on the server to find out whether you want to stop the event or not... Let's say you have a tree with nodes displayed according to user privileges and you want to make sure that the node you are about to move to another parent has compatible privileges.

Although I understand the concern (best pracitce, most of the time it's a bad design), I am quite frustrated by the approach of the ext team to synchronous requests. :)

emredagli
22 May 2009, 12:18 AM
Dear Feiichi,
This is exactly where I use it.

Since I am so bussy I could not have time to reply before.
Thanks.

In turkish (lafi agzimdan aldin...) (just said before me)

Animal
22 May 2009, 12:33 AM
I have used drag and drop with asynch requests.

You cancel the drop in the drop handler and then make the Ajax request. Perform the actual drop operation in the success callback. Simples.

You actually freeze the whole browser when forcing synchronous XHRs

emredagli
22 May 2009, 12:40 AM
With masking the tree panel Since user may redrop same node...

Animal
22 May 2009, 12:42 AM
http://extjs.com/forum/showthread.php?t=68306

feiichi
22 May 2009, 2:04 AM
Thank you, Animal.

I was actually using it somewhere else already but didn't notice it.

This works for me:
Always return false from beforenodedrop and in the success method in the ajax request call this.dropZone.completeDrop(e); to complete the canceled nodedrop assuming this points to the default event scope.

Hope this helps, emredagli

Maxrunner
12 Apr 2010, 9:25 AM
I assume the completeDrop(e) is your work feiichi, how do i manually drop the node?