Hybrid View
-
7 Jun 2007 6:56 AM #1
How to make synchronous AJAX request using Ext library?
How to make synchronous AJAX request using Ext library?
I checked the API of Connection/AJAX classes, but cannot find related configuration options? Can someone help me out here? Thanks.
-
7 Jun 2007 7:32 AM #2
As has beeb mentioned many times. Synchronous operation is neither supported nor desirable. Use callbacks to continue processing after the return of data.
-
7 Jun 2007 11:02 AM #3
Do it manually by creating a new xmlhttp object. I've only ever run into ONE situation where I actually found a synchronous xmlhttp connection to be useful, however - dynamically loading javascript code.
-
7 Jun 2007 11:22 AM #4
For example, what if I want to make several AJAX calls to download multiple XML files before the page is displayed? When using asynchronous calls to get those XML files, I have to call load_xml_b() inside the callback function of load_xml_a() .... Then, there is no single place to view the whole program logic.... Since I don't think customers will care what happens before the page is displayed, Using synchronous AJAX calls here may be helpful for a cleaner program logic.
-
7 Jun 2007 11:39 AM #5
That's a flawed approach. Similar to people that think 1000 line VB6 functions are good b/c you can 'view the whole program logic'. The reality is that you're doing event driven programming. This is not an Ext 'thing' - it's advanced UI/clientside coding in general. Think about how you handle UI interaction - there's no single place to read thru the the flow - events are fired and the flow jumps all over.
You don't have to trigger the 2nd request from the callback of the 1st unless you need to chain the requests, or stop subsequent requests after a previous failure. You could just kick off the 2 requests - they each trigger their callback fn when they're done and you go on. That may mean that you have to keep track of whether both of them finish before you do something else, but that's part of the process.
As another example (and I'm not suggesting this would be a good idea in general), what if you had 10 files to load - do you really want to chain 10 requests and manage that complexity? Or do you want to just fire 10 requests, let the browser manage sending them (2 at a time, or whatever the http limit happens to be)? Let them trigger their callbacks as they complete and then move on.Tim Ryan
Read BEFORE posting a question / BEFORE posting a Bug
Use Google to Search - API / Forum
API Doc (4.x | 3.x | 2.x | 1.x) / FAQ / 1.x->2.x Migration Guide / 2.x->3.x Migration Guide
-
7 Jun 2007 11:56 AM #6
as tryanDS said, your approach is fundamentally flawed. If you want to do this, and you want to make sure that all your requests are loaded before the page loads:
PHP Code:Ext.Ajax.request({url: 'file1.xml', callback: myCallback});
Ext.Ajax.request({url: 'file2.xml', callback: myCallback});
Ext.Ajax.request({url: 'file3.xml', callback: myCallback});
Ext.Ajax.request({url: 'file4.xml', callback: myCallback});
Ext.Ajax.request({url: 'file5.xml', callback: myCallback});
Ext.Ajax.request({url: 'file6.xml', callback: myCallback});
Ext.Ajax.request({url: 'file7.xml', callback: myCallback});
Ext.Ajax.request({url: 'file8.xml', callback: myCallback});
Ext.Ajax.request({url: 'file9.xml', callback: myCallback});
Ext.Ajax.request({url: 'file10.xml', callback: myCallback});
function myCallback(){
if(++this.counter<10) return;
// all files are done loading, do stuff
}
myCallback.counter = 0;
-
7 Jun 2007 9:38 PM #7
AJAX == Asynchronous JavaScript And Xml
-
20 Aug 2009 7:53 AM #8
-
26 Jun 2007 2:44 AM #9
I have a real need for either
a) going synchronous
b) manually blocking until the result of an aync call is available (which is more work than going synchronous and is ideologically equivalent to performing a synchronous call).
We're trying to perform an operation which yields a decision during a drag event in a Tree, in order to determine if the current drag operation was successfully completed. If we go async, I need to block until the results of the AJAX call are returned in order to return the status of the drag.
Perhaps you can suggest an approach which does not involve blocking, and can suspend the remainder of the event handlers until the result of an async call becomes available.
In other words - how do I determine the subsequent handler currently bound to the event i am processing, conditionally over-ride it, and call it with the same parameters it was originally expecting without having to bend over backwards instead of simply making an exceptional use of the *evil* synchronous attribute already built in to the XmlRequest function?
-
26 Jul 2007 2:59 AM #10
Sync for inclusion
Sync for inclusion
I agree with the these last posts. Sync/Asynch is a mechanism already built in XHR and it is there so that the programmer can chose what is best for the scenario he is implementing. Sync request have a very respectable name, RPC, and RPC have a long standing tradition. I cast my vote for the full support in Ext.
Luca


Reply With Quote