0

Hello I have ajax call in jquery

    $.ajax({
        url:   'route_process.php',
        cache: false,
        async: false,
        type:  'post',
        data:  id,
        dataType: 'html',
        success: function(data) {
            data = data.split("brk");
            sent_notification(data[1], data[2], data[3], data[4], data[5], data[6], data[7],data[8],data[9],data[10]);
            alert(data[0]); 
        },

I will get some data after success which I use for function with another ajax.

    function sent_notification(type_search, insert_id_search, date_search_array_search, from_city_lat_search, from_city_lng_search, to_city_lat_search, to_city_lng_search, counting, insert_id_search2, date_search_array_search2) {
        $.ajax({
        url:     'sent_hike_drive_notification.php',
        cache:   false,
        type:    'post',
        async: true,
        data:   {type: type_search, insert_id: insert_id_search, date_search_array: date_search_array_search, from_city_lat: from_city_lat_search, from_city_lng: from_city_lng_search, to_city_lat: to_city_lat_search, to_city_lng: to_city_lng_search, counter: counting, insert_id2: insert_id_search2, date_search_array2:date_search_array_search2},
        dataType: 'html',
        success: function(data) {
            }
        });
    }

Basically from this next ajax I dont need any success data. Could run async. But sometimes it happens I will get alert(data[0]) from first function and after confrim OK browser freezes. It looks like it is waiting for ajax finish inside sent_notification function. But I dont care result of this second ajax it is just some notification. As I said it happens only sometimes, I think it depends on second ajax execution time. How to modify my code to get success on first ajax and then execute some another ajax using data from this first ajax without any browser freezing. I thought just put async to ture to another ajax should be OK. Thanks

Vilis
  • 9
  • 5
  • Don't use `async:false` – Bergi Sep 23 '14 at 17:28
  • @Bergi You think this is enough to solve problem? I tryed and still freeze after confirm alert in first ajax. For several seconds. – Vilis Sep 23 '14 at 17:29
  • Unlikely, as you say it's the second ajax (which already uses `async:true`) which freezes. It was supposed to be a general advice. – Bergi Sep 23 '14 at 17:32

1 Answers1

1

Don't use alert as it blocks the executing thread. use console.log("message here") for debugging

reach4thelasers
  • 26,181
  • 22
  • 92
  • 123
  • 1
    You might want to also take a look at this answer about using console.log in different browsers http://stackoverflow.com/questions/4539253/what-is-console-log – Zack Sep 23 '14 at 17:19
  • Thanks I know concole.log but problem is I can click OK on this alert but after that browser still freezing. Looks like waiting for second ajax to be success? But I dont want to wait and freeze browser after first ajax finished. – Vilis Sep 23 '14 at 17:27