-
1 Feb 2012 8:55 AM #1
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(0, short.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',
title: short2,
border: false,
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
-
Best Answer Posted by tvanzoelen
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.
-
1 Feb 2012 9:30 AM #2Ext JS Premium Member
- Join Date
- Apr 2008
- Location
- Groningen - Netherlands
- Posts
- 1,034
- Vote Rating
- 27
- Answers
- 77
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.
-
1 Feb 2012 9:33 AM #3Ext JS Premium Member
- Join Date
- Apr 2008
- Location
- Groningen - Netherlands
- Posts
- 1,034
- Vote Rating
- 27
- Answers
- 77
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.
-
2 Feb 2012 4:29 AM #4
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
-
2 Feb 2012 5:28 AM #5Ext JS Premium Member
- Join Date
- Apr 2008
- Location
- Groningen - Netherlands
- Posts
- 1,034
- Vote Rating
- 27
- Answers
- 77
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]


Reply With Quote