简体   繁体   English

在第一个ajax成功之后,与其他ajax一起调用函数

[英]call function with other ajax after first ajax success

Hello I have ajax call in jquery 你好我在jQuery中有一个ajax电话

    $.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. 成功后,我将获得一些数据,这些数据可用于另一个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. 基本上从下一个ajax起,我不需要任何成功数据。 Could run async. 可以异步运行。 But sometimes it happens I will get alert(data[0]) from first function and after confrim OK browser freezes. 但是有时会发生,我会从第一个函数中收到alert(data [0]),并且在确认OK浏览器冻结之后。 It looks like it is waiting for ajax finish inside sent_notification function. 看起来它正在等待send_notification函数中的ajax完成。 But I dont care result of this second ajax it is just some notification. 但我不在乎第二个ajax的结果,它只是一些通知。 As I said it happens only sometimes, I think it depends on second ajax execution time. 正如我所说的,它仅在某些时候发生,我认为这取决于第二个ajax执行时间。 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. 如何修改我的代码以在第一个Ajax上获得成功,然后如何使用此第一个Ajax中的数据执行另一个Ajax,而不会冻结浏览器。 I thought just put async to ture to another ajax should be OK. 我以为只要把异步同步到另一个ajax就可以了。 Thanks 谢谢

Don't use alert as it blocks the executing thread. 不要使用警报,因为它会阻塞正在执行的线程。 use console.log("message here") for debugging 使用console.log(“ message here”)进行调试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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