1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    3
    Vote Rating
    0
    alexgv is on a distinguished road

      0  

    Exclamation How to get ajax request into a variable in sencha touch?

    How to get ajax request into a variable in sencha touch?


    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.



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

         var 
    buttonsGroup1 = [{
          
    text'Messages',
          
    //badge_number variable from ajax request would go here. badgeText: '2',
          
    handlertapHandler
        
    }]; 



    I just have the php script returning a number. The server responds fine and the success function works it retrieves 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

  2. #2
    Sencha User
    Join Date
    Jun 2011
    Posts
    27
    Vote Rating
    0
    Chirieac is on a distinguished road

      0  

    Default


    You could do something like this in the ajax success function:

    Code:
    success: function(response, opts) {
        var badge_number = Ext.decode(response.responseText);
        buttonsGroup1[0].badgeText = badge_number;
    },

  3. #3
    Sencha User
    Join Date
    Jun 2011
    Posts
    3
    Vote Rating
    0
    alexgv is on a distinguished road

      0  

    Default is this way better

    is this way better


    Is this way better?

    PHP Code:
      Ext.Ajax.request({
          
    url'../lib/messages.php',
          
    success: function(responseopts) {
          
    buttonsGroup1.setBadge(Ext.decode(response.responseText));
        },
            
    failure: function(responseopts) {
              
    console.log('server-side failure with status code');
        }
        });
            
             var 
    buttonsGroup1 = new Ext.Button({
            
    text'Messages',
            
    handlertapHandler
            
    }); 

  4. #4
    Touch Premium Member
    Join Date
    Mar 2011
    Location
    New Jersey, USA
    Posts
    130
    Vote Rating
    0
    jjerome is on a distinguished road

      0  

    Default


    Try this out:
    Create a global variable called badgeText with your projectname before it (shown below). Just switch 'PROJECTNAME' with your project folder's name.

    That usually works for me.

    Good luck!

    Look for my changes (orange commented text) below:


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

         var 
    buttonsGroup1 = [{
          
    text'Messages',
         
    //badgeText: PROJECTNAME.badgeText,
          
    handlertapHandler
        
    }]; 
    If you aren't working on this in a project, try just creating a regular global variable to store the badgeText.

  5. #5
    Sencha User
    Join Date
    Mar 2013
    Posts
    2
    Vote Rating
    0
    jacobnelson is on a distinguished road

      0  

    Default To get ajax request into a variable in sencha touch

    To get ajax request into a variable in sencha touch


    I got this example from Sencha tutorial


    var myRequest = Ext.Ajax.request({ url: 'myUrl', failure: function(response) { console.log(response.aborted); // logs true } });

    try this out.

    http://jnelson.in

Thread Participants: 3

Tags for this Thread