tags:

views:

342

answers:

1

Pretty simple question, I think, here's what I'm doing:

function buttonOnClick()
{
    var relevant_context = 'important data';
    $.get('/test', relevant_context, callback);
}

function callback(data)
{
    alert(this.data); // always null, expected to be 'important data'
}

I expect this.data to be the contents of "relevant_context", or what I sent in the 2nd parameter of my $.get call, but it's always null. Is there some way (besides a global variable and besides returning extra data from the server) to pass some context to the callback function?

+2  A: 

Check this old SO Answer

Marek Karbarz
+1, especially the second answer to that question, which is an excellent example of using a closure.
Jeff Sternal
Thanks, that question didn't come up in a few searches I did (and in the alternative questions summary).
Langdon