Data in Javascript Object is lost on ajax refresh

Data in Javascript Object is lost on ajax refresh

  

Hi All,

I have come across an issue in which when I am refreshing a part of a page using ajax refresh, the JavaScript object on the page is getting lost. I have a chat component which has a JavaScript object and when i change tab and come back again, the object is empty. I am instantiating the JavaScript object using JavaScript action method ( of outsystems) and then refreshing the page using ajax refresh. But post ajax refresh the object becomes empty.

Please advise.

Thanks,

Kunal

Hello Kunal,

This is how Ajax Refresh works: The server builds the piece of page you chose and sends back to browser, that will remove the old part (if it is there) and will render it again.

In this process, all IDs will potentially change.

So, if you're storing data in javascript, avoid refreshing it, or you will potentially lose it. If your JavaScript depends on binding on local elements (like buttons or inputs), that are refreshed, you will need to rebind them after ajax.

You may want to control visibility using css display property instead of removing from the HTML.

Cheers

Hi Eduardo,

Thanks for your quick reply, but now I am thinking of how to achieve my requirement.  I need to refresh the page part to show the different tab. Also, i need to have the javascript object on the chat component tab which is getting lost. I tried to re-instantiate the javascript object after the ajax refresh but that didn't help either.

Is there any other way i can achieve this.

Thanks,

Kunal

Could you explain "why" do you need to ajax refresh the tab?
By default, in the TAB widget, all the content is already there. There is no need to refresh, as the switch is carried away automatically client side through JavaScript.

I am basically changing the views which are under different tabs. One of the tab is Chat. 

Thanks,

Kunal

Kunal Priyadarshi wrote:

I am basically changing the views which are under different tabs. One of the tab is Chat. 

Thanks,

Kunal

So, don't. :)

If you need to change tab from server, run a JavaScript to click in the right tab, instead of refreshing it.

Cheers