View Full Version : Create sencha button that will poll xml to represent current status

24 Aug 2011, 1:45 PM
I am wanting to create a button on a form that will constantly poll an xml source, and update the text on a button depending on what the xml returns.

25 Aug 2011, 11:12 AM
you mean like setting the badgeText?

25 Aug 2011, 12:30 PM
Kind of, but i would like to have it constantly update without requiring the user to refresh the page

25 Aug 2011, 1:04 PM
Usually things like that require users to refresh pages. Do you ever call doLayout() after you update the text on the button? I don't think that should be an issue though.

25 Aug 2011, 1:09 PM
lol, yea it seems as if every example i have found involves refreshing the page in one way or another.

I can't say i remember calling doLayout, i'll see what i can do, but the more i spend on this the more i am starting to think that i'll have to hack something together

25 Aug 2011, 1:48 PM
Good luck!

25 Aug 2011, 1:54 PM
Thanks, i'll need it \:D/

26 Aug 2011, 5:12 PM
you could extend button to create a polling button. you could then use the DelayedTask object in sencha touch. Here is a first cut (untested).


Ext.ux.PollingButton = Ext.extend(Ext.Button, {
pollingInterval: 5000,
listeners: {
'render': function(button) {
if (button.pollingInterval > 0) {
initComponent: function() {
this.delayedTask = new Ext.util.DelayedTask(this.executePoll, this);
executePoll: function() {
url: 'your url here',
method: 'POST',
scope: this,
jsonData: {whatever you want to send down to the server},
success: function(response, opts) {
// TODO: process your response.
var text = 'set the text based on your xml response';
if (this.pollingInterval > 0) {
failure: function(response, opts) {
console.log('your error message');
// TODO: decide if you want to reschedule the polling to execute depending on the error
Ext.reg('pollingbutton', Ext.ux.PollingButton);