Home Multiple Async AJAX with jquery .append in it
Reply: 0

Multiple Async AJAX with jquery .append in it

user1315
1#
user1315 Published in May 23, 2018, 7:19 am

I have several ajax which append it result to HTML table. the example of code is like this

$.ajax({
    url: '<?php echo Url::toRoute('booking/get_1_rate'); ?>',
    type: 'GET',
    dataType: 'json',
    async: true,
    data:{          
    },          
    success: function(data){
         display_rate(data);
    }
}); 

$.ajax({
    url: '<?php echo Url::toRoute('booking/get_2_rate'); ?>',
    type: 'GET',
    dataType: 'json',
    async: true,
    data:{          
    },          
    success: function(data){
         display_rate(data);
    }
 });    

function display_rate(data)
{
    $.each(data.departure, function(index, value)
    {
        html_depart = "<tr><td>value.airline_code</td></tr>";
        $('#table_body_search_flights_depart').append(html_depart);
    });    
}

The problem is the result which appear in HTML table is depends on which ajax finish first, then the result of late ajax will not appear in HTML table. It seems like the jquery .append() just append the first ajax result.

I check the string that contain html in second ajax and its fine / success, but the string not append to html in second ajax. Only the string in first ajax that append to html

Is there any idea?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.626807 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO