1. #1
    Sencha User Gr3yh0und's Avatar
    Join Date
    Aug 2011
    Location
    Germany
    Posts
    10
    Vote Rating
    0
    Gr3yh0und is on a distinguished road

      0  

    Post Answered: Execution order?

    Answered: Execution order?


    Hey guys,

    I've got another problem here. I'm doing some asynchron AJAX requests which destroy my function logic...
    The Javascript gets an Location ID from external sources and makes a query to the DB to get the location name. Then the number of devices in that location is queried.

    BUT: The first tab in the tabpanel should display this data and the second query is too slow, so "undefined" is displayed... When i change the tabs, the activate event gets called and it is displayed correctly.

    PHP Code:
    // Example
    // Declare Variables
    var pcs;
    var 
    short;

    // Get Location name
    Ext.Ajax.request({
                
    url:'config/api_mysql.php?do=read',
                
    params: { select'id, short'table'location'where'id = ' getid },
                
    success:function(res){
                    var 
    response Ext.JSON.decode(res.responseText);
                    
    short response.results['0'].short;
                }
            }); 


    Ext.onReady(function() {

    // Cut 2 symbols from location name (dirty!)
    var short2 short.substring(0short.length-2);

    // Get amount of desktop devices in location using Location Name
    Ext.Ajax.request({
            
    url:'config/api_mssql.php?do=readdumb',
            
    params: { query'SELECT count(b.buildingname) FROM deviceMDLogGroup c INNER JOIN Device d ON (c.DeviceID = d.DeviceID) INNER JOIN Building b ON (c.BuildingID = b.BuildingID) WHERE b.buildingname LIKE "' short2 '" AND devicetypeid = 1' },
             
    success:function(res){
                  var 
    response Ext.JSON.decode(res.responseText);
                  
    pcs response.results['0'].computed;
             }
    }); 


    // Show data in tab
    tabpanel.add({
                
    itemID'details',
                
    titleshort2,
                
    borderfalse,
                
    listeners: {
                    
    // reload on change
                    
    'activate': function(tab) {
                        
    tab.remove('details');
                        
    tab.add({ 
                            
    xtype'component',
                            
    id'details',
                            
    html
                            
    '<b>Amount PCs:</b> ' pcs
                            
    ,
                            
    style'margin: 20px; padding:20px;'
                        
    });
                    }
                }            
            }); 
    Bye
    Gr3yh0und

  2. why not add the tab in the success function of the ajax callback? the adding of your tab will not wait for the ajax call to return, unless you set the ajax request on synchronous.

  3. #2
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,114
    Answers
    83
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    why not add the tab in the success function of the ajax callback? the adding of your tab will not wait for the ajax call to return, unless you set the ajax request on synchronous.

  4. #3
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,114
    Answers
    83
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    by the way... you should never put such a db query in the ajax call in a parameter you send over the web. With the sample you posted its possible for hackers to delete your database.

  5. #4
    Sencha User Gr3yh0und's Avatar
    Join Date
    Aug 2011
    Location
    Germany
    Posts
    10
    Vote Rating
    0
    Gr3yh0und is on a distinguished road

      0  

    Default


    Thanks, I will give that a try later on...

    Actually it's just for internal services and holds no quite important data, so security is not that thing. ExtJS looks great but misses backends for SQL! Is there a secure Backend-API for MSSQL and MySQL?
    Bye
    Gr3yh0und

  6. #5
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,114
    Answers
    83
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    I think most users have a multi tier system.

    [client] <---> [middle] <--> [DB]

    Extjs should be used between client and middleware I think. The middleware or businesslayer communicates with the db and returns json to the client wich you display in the client UI

    or
    Code:
    [client] <-- extjsconfigs--->  [uigenerator]   
                                         |            
             <----- jsondata --->  [middleware]  <---->   [db]

Thread Participants: 1