Using an inline callback function
Having a really hard time getting this to work, could use a little guidance on what I'm doing wrong....the code should be fairly self explanatory....
- function callbackTest(file, callback)
- {
- $.get
- (
- file,
- function(data)
- {
- // do something
- callback.call(data);
- }
- );
- }
Then call it like.....
- $(document).ready
- (
- function()
- {
- callbackTest
- (
- "file.html",
- function(data)
- {
- alert(data);
- }
- );
- }
- );
When I try this, I get an error from the callbackTest function, "callback is not a function".
Obviously this isn't the correct way to do what I want (or it would work!), but it should be pretty clear from this exactly what I'm trying to achieve. Any help at all would be appreciated.
Cheers.