Ajax request are not async

后端 未结 4 1000
既然无缘
既然无缘 2021-01-06 09:48

I have an ajax problem:

foreach(ids as id){
  $.ajax({
    url:\'script.php\',
    data:\'id=\'+id,
    cache:false,
  });
}

If I loop 6 ti

4条回答
  •  臣服心动
    2021-01-06 10:31

    Why not sending all id's to the script and then loop them is faster en more accurate..

    Javascript:

    // you can send the whole array in once i think not for sure
    $.ajax({
        url:'script.php',
        type: 'POST',
        data: ids,
        cache:false,
        success:function(msg)
        {
            // when done
        }
    });
    

    script.php:

    foreach($_POST as $id)
    {
        [............] // do your thing
    }
    

提交回复
热议问题