small logo

melfneerg.com

 - 'cos life is like that


[Blog]  [Pictures]  [Links]  [About
About the Author
Tudor Davies

author Tudor is a techie turned manager who fights like mad to keep his tech skills honed and relevant. Everything from web hosting, networking, *nix and the like. Constantly developing and co-ordinating with others to make the web a better (and easier to use) place.

Nest your jQuery .loads...

Tuesday, 4th Jun 2013  Posted @ 09:08

I was having a nightmare loading some information using jQuery into a webapp.

This works:

function getTransactions() {
var oAccount = document.getElementById('account').value;
$('#transtable tbody').load('api.php?action=gettransactions&account=' + oAccount);
$('#balancetable tbody').load('api.php?action=currentbalance&account=' + oAccount);
}
However, the first request was taking 6-7ms but the second request was always taking 1.01s regardless of the order I put them.

So I did some googling around and decided to nest the requests:
function getTransactions() {
var oAccount = document.getElementById('account').value;
$('#transtable tbody').load('api.php?action=gettransactions&account=' + oAccount, function () {
$('#balancetable tbody').load('api.php?action=currentbalance&account=' + oAccount);
});
}
Now both requests complete in 8ms!

[ no comments : Add ]

Tweet




layout and initial css based on the Qtractor page