Reputation: 677
The following code called when clicked a button and call the insert _all function that is an ajax function. In success I put an alert but not working the json call liquidations_a_insert_all.jsp is working fine.
$(document).ready(function() {
$('#click1').click(function(event) {
var auditorid = $('input:hidden[id=Wauditorid]').val();
$.ajax({
type: 'GET',
url: 'groupauditors.jsp',
data: {
Woauditorid: auditorid
},
dataType: 'json',
success: function(data) {
$.each(data, function(index, element) {
var currRow = $("#tr0").clone().appendTo($('#items')).attr('id','tr' + (index + 1));
currRow.find('td:eq(0)').html(index + 1);
currRow.find('.subgroupid').html(element.subgroupid);
currRow.find('.auditorid').html(element.auditorid);
insert_all(element.auditorid, "", "");
});
}
});
});
});
that call the insert_all(element.auditorid, "", "");
function insert_all(auditorid, onSuccess, onFail) {
$.ajax({
type: 'GET',
url: 'liquidations_a_insert_all.jsp',
data: {
Wauditorid: auditorid
},
dataType: 'json',
success: function(data) {
alert("insert_all");
//$( 'table tbody tr td:last-child').html(data.inserted);
}
});
}
Any idea?
Upvotes: 1
Views: 78
Reputation: 261
I hope Using async:false,
in Both ajax Function
$(document).ready(function() {
$('#click1').click(function(event) {
var auditorid = $('input:hidden[id=Wauditorid]').val();
$.ajax({
type: 'GET',
url: 'groupauditors.jsp',
data: {
Woauditorid: auditorid
},
async:false,
dataType: 'json',
success: function(data) {
$.each(data, function(index, element) {
var currRow = $("#tr0").clone().appendTo($('#items')).attr('id','tr' + (index + 1));
currRow.find('td:eq(0)').html(index + 1);
currRow.find('.subgroupid').html(element.subgroupid);
currRow.find('.auditorid').html(element.auditorid);
insert_all(element.auditorid, "", "");
});
}
});
});
});
function insert_all(auditorid, onSuccess, onFail) {
$.ajax({
type: 'GET',
url: 'liquidations_a_insert_all.jsp',
data: {
Wauditorid: auditorid
},
async:false,
dataType: 'json',
success: function(data) {
alert("insert_all");
//$( 'table tbody tr td:last-child').html(data.inserted);
}
});
}
Upvotes: 1