Reputation: 1334
I've the following code:
<script>
function GetDetails(id) {
$.ajax({
url: "@Url.Action("EditRecord","TeamPlans")" + "/" + id,
type: "GET",
contentType: "application/json;charset=UTF-8",
dataType: "json",
success: function (response) {
$('#hfId').val(response.ActivityPlanId);
$('#txtActivityPlanName').val(response.ActivityPlanName);
$("#CountryId").val(response.OrganizationNumber);
$('#StateId').val(response.Assignee);
$('#modal-Update').modal('show');
},
error: function (response) {
alert(response.responseText);
}
});
return false;
}
</script>
Then I also have the following code:
<script>
$(document).ready(function () {
$("#CountryId").change(function () {
$.get("@Url.Action("GetStateList","TeamPlans")", { sOId: $("#CountryId").val() }, function (data) {
//$("#StateId").empty();
$.each(data, function (index, row) {
$("#StateId").append("<option value='" + row.PositionNumber + "'>" + row.Name + "</option>")
});
});
})
});
My question is, how can I execute the second script on first script before the modal-update show? #CountryId
already filled when execute the url: "@Url.Action("EditRecord","TeamPlans")" + "/" + id,
Please help.
Thank you.
Upvotes: 0
Views: 67
Reputation: 18973
I assumption your button to show detail has class .detail, you can bind ajaxStart
to .detail button as
$(".detail").ajaxStart(function(){
$("#CountryId").change(function () {
$.get("@Url.Action("GetStateList","TeamPlans")", { sOId: $("#CountryId").val() }, function (data) {
//$("#StateId").empty();
$.each(data, function (index, row) {
$("#StateId").append("<option value='" + row.PositionNumber + "'>" + row.Name + "</option>")
});
});
})
})
More at https://api.jquery.com/ajaxStart/
Upvotes: 1