Dear Lin,
your question is not very clear.
What you want is :
* Build an application, probably in rails (you should have asked on
that list btw).
* Use XmlHttpRequest (the xhr you mention) to submit some complex
operation.
* Operations should be non-blocking and return a value to the emitter.
What you need in your page, is two XHR. One that submits calculations,
and the second that periodically gets the results.
In your controller, you need two methods. "submit" and "response" for
example. Submit launches a new Thread in which it does the
calculations. Once finished, it fills the user's session for example,
or stores it in a class variable. Response looks in the sessions for
the results. Now I'll let you the pleasure of the implementation
Cheers,
zimbatm