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....the $.get isn't important, just an example with some asynchronous execution to demonstrate the point of this function, but it could be anything at all, don't focus on that please :)
function callbackTest(file, callback)
{
$.get
(
file,
function(data)
{
// do something
callback.call(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.
Question
AJCrowley Esq
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....the $.get isn't important, just an example with some asynchronous execution to demonstrate the point of this function, but it could be anything at all, don't focus on that please :)
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.
Link to comment
Share on other sites
3 answers to this question
Recommended Posts