Is there a difference between this:
var onClick = function() { var image = ..... $.post('/..../...', null, function(data) { myCallback(data, image); } ); }
and
var onClick = function() { this.image = ..... $.post('/..../...', null, function(data) { myCallback(data, this.image); } ); }
I am using the ‘this’ way, and for some reason any parameter I pass into myCallback is null??
If I output the variable before the $.post call using alert, I get a value so its not null?
At the time….
…will be executed (after the ajax call has completed), the execution context is changed. It will be inside a jQuery object context. So at that point, this === jQuery, which as you already saw, has no image property. Hence, the error.
By the way, google for JavaScript closures and try to understand them. It’s exactly what your problem is all about.