Could anyone explain to me why the following is happening. First of all see my code below. Trying to get data via a JSON request and save it for later use.
var entities;
//@jsonGetEntities is an url build by asp.net MVC and this works
$.getJSON("@jsonGetEntities", function(getdata) {
entities = getdata;
//I would expect that this is the first alert
alert(entities + "first");
});
//I would expect that this is the second alert
alert(entities + "second");
However, the alert that I would expect to be first comes second and entities
is actually filled.
In the last alert entities
is not filled.
I can't seem to understand why my json is not saved to the var and why an alert that is called later is executed earlier? Could you also give me a possible other solution?