简体   繁体   中英

Calling ajax function from ajax

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?

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);
                    }
     });
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM