I've made myself this small script to return a value from the database but I found out that at the end of the $.ajax()
function, the value stored was no longer kept. How could we store it so that we could use outside $.ajax()
. The value returned from the server is simply a number 23.
$(function(event) {
var valueToBeUsed;
var value;
$.ajax({
type: "GET",
url: "get.php",
data: {value: "like"},
success: function(data) {
value = data;
alert(value); //first time alert shows "23"
}
});
valueToBeUsed = value;
alert(valueToBeUsed); //returns "undefined"
});