I have a long loading for loop inside a function in one of my model in my Joomla component. In order to gauge the progress, I wanted to make a progress bar using ajax and javascript as the request is being processes.

As a start, I made a simple ajax call to a function of one of the controllers which contains the following code:

Here I'm using getSession, but as far as I have understood, session and userstate or almost the same, except for userstate allowing some other things and saving the variables in the registry. I have tried both, and the results are the same.

The get comes from inside the foor loop of my function inside the model, that does the heavy computation, and lookings something like this:

So far so good, the problem is that the user state does not get updated when the script runs. It seems like it only gets updated after it is done. Now what I suspect is that joomla puts these values into a buffer that it sets only when a pending request is done.

This is unfortunately no good for what I am trying to do.

Do anyone have any suggestion as to what I could do instead. It would be best if I could do this without modifying any default setting in Joomla.

edit: Ok, I've noticed something new, when the php function is done running, I output some feedback that I get from the userstate which I set at the end of the method in my model that does the heavy calculation. I've noticed that this feedback is displayed correctly, but only sometimes.

That is, some times it displays the feedback from the previous processing, some times it displays the feedback from the current one. Sometimes I can refresh the window after a couple of seconds and the correct feedback will show (everytime I refresh, getUserstate on the feedback is called), other times I have to rerun the script n times before the correct feedback shows.

It seems to behave in an erratic and random way. Maybe I have accidentily deleted some table values or changed some settings in Joomla that could cause this? Does anyone have an idea?

Also, I read that if the registry for some reason was not set (setUserstat will do nothing in this case), I could do:

1 Answer
1

Well I believe I had a similar problem once where I got random results. For me, the solution was using a synchronous request (instead of the asynchronous one, which you are using, too, if I am not mistaken). This is somewhat decreasing performance, but will force the request to be executed in an orderly fashion.

I just found this page which explains and gives some examples. Try just changing