Tuesday, 29 January 2019

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....

enter image description here

Requirement :

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

enter image description here

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);

?>



from Display Progress message after calling api url

No comments:

Post a Comment