I know that this question has been asked million times so my apologies.
I looked at all other examples and I dont understand why the following code is not working now.
I get undefined alert box when I place it outside the CheckinMap function.
Why is it?
$(document).ready(function() {
var MapData;
$(function CheckinMap() {
$.ajax({
type: "GET",
url: "content/home/index.cs.asp?Process=ViewCheckinMap",
success: function (data) {
MapData = data;
},
error: function (data) {
$("#checkinmap").append(data);
}
});
});
alert(MapData);
});
MapDatais undefined because thealertis executed while the ajax call is still running (ajax is asynchronous) and the response is not yet available. So change your code in this wayor continue the code execution calling another function
or use deferred objects (on jQuery 1.5+)