0

What I am trying to do is is get the information I have in my ajax request as the badgetext number

Here is where I am trying to do it. This seems simple, but I cant figure it out.

    Ext.Ajax.request({
      url: '../lib/messages.php',
      success: function(response, opts) {
      var badge_number = Ext.decode(response.responseText);
      console.dir(badge_number);
},
    failure: function(response, opts) {
    console.log('server-side failure with status code');
}
});

     var buttonsGroup1 = [{
      text: 'Messages',
      //badge_number variable from ajax request would go here. badgeText: '2',
      handler: tapHandler
    }]; 
Alex
  • 530
  • 3
  • 12
  • 28
  • Not much to go on here. What is the response from the PHP script? I would open up the page and test it in Chrome/Safari using the JS debugging tools. It'll allow you to see what the server is responding with, and inspect the state in your success function. – mistagrooves Jun 21 '11 at 16:20
  • @mistagrooves I just have the php script returning a number. The server responds fine and the success function works it retrives the data. But I want the data that the success function gets from the php script to be the badgeText. My problem is that I do not know how to put that data into badgeText which is in the variable buttonsGroup1 – Alex Jun 21 '11 at 17:07
  • Hey pls go through this http://stackoverflow.com/questions/9563417/how-to-consume-soap-web-service-in-sencha-touch and give your valuable response... – himanshu Mar 05 '12 at 10:39

1 Answers1

1

Ah ok, I misread the question.

So the most straight forward way to put the badge text on the button is to create a closure.

var button = new Ext.Button({
  text: 'Messages',
  handler: tapHandler});

Ext.Ajax.request({
  ....
  success: function(response, opts){
     button.setBadge(Ext.decode(response.responseText));
  }
  ...
});

This will cause the badge text to be updated when the AJAX call completes. You can then add the object to a Panel or Toolbar after the AJAX request code as you would have before.

If you absolutely have to have the badge text on the button before it is created, you will need to create the button group inside the success function and assign/add it to the appropriate container object.

Community
  • 1
  • 1
mistagrooves
  • 2,337
  • 15
  • 16
  • that worked perfect. Just out of curiosity that same method would be used if I was updating a panel or anything else. – Alex Jun 21 '11 at 17:37
  • @Alex yeah, you could also do it in the same manner. You could also find a reference to the component that needs updating in another method as well like Ext.getCmp("id") or this.items.getAt(n). It really depends on the situation. – mistagrooves Jun 21 '11 at 18:03
  • Hey pls go through this http://stackoverflow.com/questions/9563417/how-to-consume-soap-web-service-in-sencha-touch and give your valuable response... – himanshu Mar 05 '12 at 10:39