tags:

views:

129

answers:

2

Hi there,

I'm using dojo for our UI's, and would like to load certain part of page contents in sequence. For example, for a certain stock, I'd like to load stock general information, such as ticker, company name, key stats, etc. and a grid with the last 30 days open/close prices. Different contents will be fetched from the server separately. Now, I'd like first load the grid so the user can have something to look at, then, say, start loading of key stats which is a large data set takes longer time to load. How do I do this. I tried: dojo.addOnLoad(function() {

startGrid(); //mock grid startup function which works fine getKeyStats(); //mock key stat getter function also works fine });

But dojo is loading getKeyStats(), then startGrid() here for some reason, and sequence doesn't seem be matter here. So how I can control the loading sequence at will? Thanks in advance!

David

A: 

The sequence doesn't matter because they are asynchronous requests; they appear in the same order as responses were received from the server, which is not necessarily the same order as they were called in.

To load them in the correct order, make your requests as normal. Add a callback for a successful response that places the response data into a shared bucket in any order. Once you have the proper number of responses (check it at the end of your callback), start inserting data into the page in any order you like.

Jeff Ober
Hi jeff, thanks for your reply, could you expand on your answer? so you're saying I have to load all the contents first, then insert them into appropriate places? What I really want is to load the page contents asynchronously, but load the slow loading contents the latest.
David Zhao
Ah, that sounds like you have sync requests going on and the slow ones are starving the page. There is an ajax request parameter that you must explicitly use (I think) to tell dojo to execute requests asynchronously.
Jeff Ober
do you happen to know the parameter setting? any example? Does asynchronous request mean random? so if I have multiple requests, I wouldn't know which one gets processed first in AJAX?
David Zhao
A: 

you may want to look at dojo.publish and use a pub sub pattern to loosely couple these events so that you can order them. Pub sub will allow you to make the request and listen for all topics to fire. With this you could call the request asynchronously and load the widgets in there respective place while styling them hidden and use the pub sub to make them visible based on a sequence of topic publications.

kls
I have used dojo's subscribe/publish before, need to try this. But I think since the data for different part of the page need to be processed at different times, that order I still can not control, right?
David Zhao