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.
resultsto be the string 'results' but you never set it to that in the code? You also seem to want your AJAX callback to have access to the original value ofdatawhile you go off on modifydatawhile the async op is completing? Am I getting that correctly?results- passing of the callback result is automatically handled by jQuery. My problem is how can I pass in the current state ofdatasuch that it does not override results if passed in like in the second example.