I am trying to use my response from the ajax call to loop through the response outside of the ajax call. In the code I have I only see the object it self and it starts to for-loop through the decription of the object not what is in it. And how do I stop it from refresh the page afterwards?
$(document).ready(function() {
var jsonResult;
$.ajax({
type: 'GET',
url: 'http://example.com/test.json',
data: {
get_param: 'value'
},
dataType: "json",
success: function(data) {
jsonResult = data;
}
});
$("#form").submit(function(jsonResult) {
var userAnswer = $("#useranswer").val();
for (var key in jsonResult) {
if (jsonResult[key] === userAnswer) {
$("#confirmed").html("Yes");
break;
} else {
$("#confirmed").html("No");
}
}
return false;
});
});