Have a look at the following examples:
var data = "abc";
$.post(ajaxurl,data,function(results) {
console.log(data);
console.log(results)
} ,'JSON');
data = "ghi";
Result:
data: "ghi"
results: "results"
Passing data:
var data = "abc";
$.post(ajaxurl,data,function(results) {
console.log(data);
console.log(results)
} (data) ,'JSON');
data = "ghi";
Result:
data: "abc"
results: "abc"
However what I want to achieve is to pass the local variable data
but recieve the passed variables from the callback anyway.
Desired output:
data: "abc"
results: "results"
In PHP this would be something like:
function abc($result) use ($data) {
//...
}
How can I achieve this behaviour?
Edit - Clarification: I want to pass the current state of a local variable to an aynchronous request callback with arguments.