I want to set a localstorage inside .done method when user's answer is correct. Then i want to get
that local storage object and use that outside of the done
method. How is that possible? Below is what i am trying without success.
data.color is a string
$.ajax({
type: "POST",
url: "validation.php",
dataType: "json",
data: $("input").serialize(),
}).done(function(data) {
if (data.answer) { //if answer is correct
localStorage.setItem("ColorStorage", data.color); //set a local storage with the variable data.color
}
});
//outside of ajax
if (localStorage.getItem("ColorStorage") > 1)
$("#result").append(localStorage.getItem("ColorStorage"));