Q:

Display Progress message after calling api url

we select checbox & onclick button "Show Status" , I am calling external webservice api url & updating the "status" column [4th in below image] values in Database..... 
once we got success response we are displaying alert message.... 

Requirement :
but now i want to display Progress like "1% completed , 2 % completed" , so on.... :

status page
<button type= "button" id="show_status" >Show Status</button>

script
$('#show_status').click(function()
 { 
    var selected = []; 
    $('.assigneeid-order:checked').each(function() 
       { 
         selected.push($(this).val()); 
         $('.assigneeid-order').prop('checked', false);
       }); 

var jsonString = JSON.stringify(selected); 

$.ajax
  ({ 
type: "POST", 
url: "api.php", 
data: {data : jsonString}, 
     success: function(response)
       { 
          response = $.parseJSON(response);
          alert("completed");
          $.each(response, function(index, val)
             { 

                   $("#"+index+"").html(val);
                   $("#"+index+"").html(val.status); 

             }); 
        } 
  }); 

});

api.php
 <?php

$data = json_decode(stripslashes($_POST['data'])); 
$response = array(); 

foreach($data as $id){ 

$post_data['username']='a';
$url = 'https://plapi.ecomexpress.in/track_me/api/mawbd/'; 
$ch = curl_init(); 
curl_close($ch); 

$orderResults=$xml=simplexml_load_string($output);
//print_r($orderResults); die;
    foreach($orderResults->object as $child)
    {
      $status=(string)$child->field[10];         
      break;
     }

$statusfinal = str_replace('<field type="CharField" name="status">','',$status); 

if($statusfinal!='') 
{ 
$sqlecom = "UPDATE do_order set in_transit='".$status."' where tracking_id=".$orderid;
//echo $sqlecom;

$db_handleecom = new DBController(); 
$resultecom = $db_handleecom->executeUpdate($sqlecom); 
} 
$response[$orderid] = [ 'status' => $status ];
}
echo json_encode($response);

?>

A:

Please try this script and code 
$('#show_status').click(function()
 { 
    var selected = []; 
    $('.assigneeid-order:checked').each(function(){ 
        selected.push($(this).val()); 
        $('.assigneeid-order').prop('checked', false);
    }); 
    var count = selected.length
    var perPlush = 100/count;
    var per = 0;
    for (var i = 0; i <= count; i++) {
        $.ajax
        ({ 
            type: "POST", 
            url: "api.php", 
            data: {id : selected[i]},               
            success: function(response)
            { 
                response = $.parseJSON(response);
                $.each(response, function(index, val)
                { 
                    $("#"+index+"").html(val);
                    $("#"+index+"").html(val.status); 
                });
                per = per + perPlush;
                console.log(Math.round(per) + " % Complated");
                $("#progress").html(Math.round(per) + " % Complated"); 
            } 
        });     
    }
});

Your api.php file
<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ALL & ~MYSQLI_REPORT_INDEX);

require_once("dbcontroller.php");
$db_handle = new DBController();

$id = $_POST['id']; //960856092
$response = array(); 

$orderid = $id; 
$hide = '';
$post_data['awb']=$orderid;  
$url = 'https://plapi.ecomexpress.in/track_me/api/mawbd/'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, "http://plapi.ecomexpress.in/track_me/api/mawbd/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
$output = curl_exec ($ch); 
curl_close($ch); 

$orderResults=$xml=simplexml_load_string($output);
if($orderResults){
    foreach($orderResults->object as $child)
    {
        $status=(string)$child->field[10];       
        break;
    }

    $statusfinal = str_replace('<field type="CharField" name="status">','',$status); 

    if($statusfinal!='') 
    { 
    $sqlecom = "UPDATE do_order set in_transit='".$status."' where tracking_id=".$orderid;
    //echo $sqlecom;

    $db_handleecom = new DBController(); 
    $resultecom = $db_handleecom->executeUpdate($sqlecom); 
    } 
    $response[$orderid] = [ 'status' => $status ];  
}
else{
    $response[$orderid] = ['status' => 'Order already placed'];
}
echo json_encode($response);
?>

