View Full Version : Execution order?

1 Feb 2012, 8:55 AM
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.

// Example
// Declare Variables
var pcs;
var short;

// Get Location name
params: { select: 'id, short', table: 'location', where: 'id = ' + getid },
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
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' },
var response = Ext.JSON.decode(res.responseText);
pcs = response.results['0'].computed;

// Show data in tab
itemID: 'details',
title: short2,
border: false,
listeners: {
// reload on change
'activate': function(tab) {
xtype: 'component',
id: 'details',
'<b>Amount PCs:</b> ' + pcs
style: 'margin: 20px; padding:20px;'

1 Feb 2012, 9:30 AM
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
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
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?

2 Feb 2012, 5:28 AM
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


[client] <-- extjsconfigs---> [uigenerator]
<----- jsondata ---> [middleware] <----> [db]