How to set global variable.
$(document).ready(function() {
$("a.action").click(function(event) {
var tempResponse = "";
$.get("", function(response){
tempResponse = response;
});
alert("response " + tempResponse );
}
//todo use response to manipulate some data
});
I declared globa variable tempResponse
. and I set in get call back function.
tempResponse = response;
but while I try to alert the response no data displayed. I also try this solution. I change the variable declaration
become $.tempResponse
and change the set script become $.tempResponse = response;
But it doesn't work to.
Why this could be happened ?