Update client without refreshing
Added by Mahmudul hasan over 6 years ago
I want to update some controls only in the GUI after the server post. But looks like it's refreshing the full page. Which i don't want.
void MyTempalte::UpdateData() {
bindString("temperature", std::to_wstring(model.Temperature()), TextFormat::Plain);
Wt::WApplication::instance()->triggerUpdate();
}
My html content has a bootstrap tab control which contains many other controls in each tab. I want to get the data i am polling on server. Post i working and sending data to the client but it's reloading the home tab.
How can i stop the reload?
Replies (3)
RE: Update client without refreshing - Added by Roel Standaert over 6 years ago
If you use bindString
, this will rerender the template. If you want to update a part of a template without rerendering the template you'll have to put it in another widget. In your case I would recommend that you bind a WText
to temperature and update its contents with setText()
.
Regards,
Roel
RE: Update client without refreshing - Added by Mahmudul hasan over 6 years ago
I have many controls in my html template where i want to the values. I placed variables ${var} to showing the values. In my case I can't afford to add so many widgets for UI controls. Is there any alternative. I want Ajax like behavior.
RE: Update client without refreshing - Added by Roel Standaert over 6 years ago
Wt operates with a mapping between widgets and (a collection of) DOM elements. If you want to only modify a particular DOM element, then the only way to make that work is to have that DOM element correspond to a widget.
In this case, you'd need a <span>
element in the DOM, represented as a WText
in Wt's widget tree.
What makes having so many widgets unaffordable to you? You could write your own JavaScript to update certain parts of your application, but that very much goes against the typical way things are done with Wt.