On my click event, I am trying to open a bootstrap modal. Modal has some values, which I am trying to get from ajax call using getJSON. Problem is that the getJSON is fired at last when the jQuery function ends.
Here is my code:
$('.poplinks').popover().parent().on('click', '.insert-submission', function () {
var baKey = 8701;
var obj;
$.getJSON('/urltogetobjectwithvalue/', {id: baKey}, function (result) {
debugger; //it comes here at last after modal('show') executes
obj = result;
});
debugger; //first it come here
$("#span_unk_sub_baid").html(baKey);
if (obj !== undefined)
$("#span_unk_sub_baid").append(' Eff Date: ' + obj.EffectiveDate);
$('#dialog_ins_purc').modal('show'); //now it will go to $.getJSON
});
I want to show some values which I am getting from JSON call. After the modal is loaded, then it goes to get values. How to I make sure, json call is made in the same sequence I want. Please help.