Ajax中的Ajax无法正常工作

I have a function that calls an ajax, inside that ajax another ajax needs to be executed. In the below code I gave my full function. Just to ensure that everything but the 2nd ajax works perfectly, I should point you out that before the 2nd ajax call there is an alert() function which works. That means everything works if I comment the 2nd ajax call. If I uncomment it then after the first alert a second alert should appear saying 'inside 2nd call', but nothing happens. Got any suggestions?

function get_employee_list(Parameter){

$.ajax({
    url: 'resource/php/search_profile.php',
    type: 'POST',
    data: { var1 : Parameter},
    async: false,
    success: function (response) {
        //alert(response);
        reset_search_table();
        $(response).find('employee').each(function() {
            var ebasp_id = $(this).find('ebasp_id').text();
            var ebasp_name = $(this).find('ebasp_name').text();
            var ebasp_gender = $(this).find('ebasp_gender').text();
            var ebasp_category = $(this).find('ebasp_category').text();
            //var ebasp_region_type = $(this).find('ebasp_region_type').text();
            //var ebasp_region_name = $(this).find('ebasp_region_name').text();
            var code_sub_region = $(this).find('ebasp_sub_region').text();
            var code_location = $(this).find('ebasp_location').text();
            var code_office = '';

            if (code_location === '0')
                code_office = code_sub_region;
            else
                code_office = code_location;
            var office = '';

            //alert('before 2nd call -- '+code_office);
            $.ajax({
                url: 'resource/php/show_cost_center_name.php',
                type: POST,
                data: { var1 : code_office},
                success: function(response){
                    office = response;
                    alert('inside 2nd call');
                }
            });

            var ebasp_designation = $(this).find('ebasp_designation').text();
            var ebasp_date_of_joining = $(this).find('ebasp_date_of_joining').text();
            var ebasp_grade = $(this).find('ebasp_grade').text();
            var ebasp_slab = $(this).find('ebasp_slab').text();
            var ebasp_basic = $(this).find('ebasp_basic').text();
            var ebasp_photo_upload = $(this).find('ebasp_photo_upload').text();
            var ebasp_created_on = $(this).find('ebasp_created_on').text();
            var ebasp_created_by = $(this).find('ebasp_created_by').text();

            $("#search_table").show();
            $('<tr></tr>').html('<td>'+ebasp_id+'</td>'+
                                '<td>'+ebasp_name+'</td>'+
                                '<td>'+ebasp_gender+'</td>'+
                                '<td>'+ebasp_category+'</td>'+
                                '<td>'+office+'</td>'+
                                '<td>'+ebasp_designation+'</td>'+
                                '<td>'+ebasp_date_of_joining+'</td>'+
                                '<td>'+ebasp_grade+'</td>'+
                                '<td>'+ebasp_slab+'</td>'+
                                '<td>'+ebasp_basic+'</td>'+
                                '<td>'+ebasp_created_on+'</td>'+
                                '<td>'+ebasp_created_by+'</td>').appendTo("#search_table");
        });
    },
    cache: false,
});return false;
}
查看全部
weixin_33712987
weixin_33712987
2016/02/12 09:26
  • ajax
  • 点赞
  • 收藏
  • 回答
    私信

0个回复