Changed code in order to execute ajax only once.

And reuse data.