Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  171] [ 1]  / answers: 1 / hits: 46613  / 13 Years ago, fri, june 3, 2011, 12:00:00

How can I make synchronous ajax requests in EXT JS?



For example, given this code:



test1();
ajaxRequest(); //Ajax Request
test2();


The test2 function is executed without even finishing the execution of ajaxRequest(), which has an Ext.Ajax.request call .



How can I make text2() execute only after the ajaxRequest() function has been executed?



I understand that one way of doing it is to call the test2 function in a callback, but I have some dependencies and a lot of code that has to be executed after the ajax request, in a synchronous manner. Can you please help me with the best solution?


More From » ajax

 Answers
4

I needed something similar and after looking the source code of Ext.Ajax.request() and Ext.data.Connection, I found that they check for a async attribute, on the request() method, so, it's actually possible to make a synchronous request, like this:



var response = Ext.Ajax.request({
async: false,
url: 'service/url'
});
var items = Ext.decode(response.responseText);


It seems this async attribute is not documented, so... of course... be aware that it may change in future releases.


[#91871] Thursday, June 2, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zane

Total Points: 471
Total Questions: 94
Total Answers: 91

Location: Bahrain
Member since Sun, Mar 27, 2022
2 Years ago
;