刷新页面前显示状态

时间:2018-03-05 05:56:15

标签: javascript php jquery ajax

当我选择复选框并点击“显示状态”按钮时,仅在我刷新页面后显示状态值,但我需要在刷新之前显示 页面。

enter image description here

HTML

<td>
  <input type="checkbox" id="assigneeid-<?php echo $orderrecords[$k][" tracking_id "]; ?>" onclick="assignorderids('<?php echo $orderrecords[$k][" tracking_id "]; ?>')" name="checkassigneeid" class="assigneeid-order" value="<?php echo $orderrecords[$k]["
    tracking_id "]; ?>">
</td>

的javascript

$('#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);
      $.each(response, function(index, val) {
        $("#" + index + "").html(val);
      });
    }
  });
});

api.php

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

foreach($data as $id) {
  $orderid = $id;
  $hide = '';
  $post_data['username'] = 'admin';
  $post_data['password'] = 'admin123';
  $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);

  foreach($orderResults - > object as $child) {
    $status = (string) $child - > field[10];
    break;
  }
  $res = explode("\n", $output);

  if (!isset($res[13])) {
    $res[13] = null;
  }

  $statusfinal = str_replace('<field type="CharField" name="status">', '', $status);
  if ($statusfinal != '') {
    $sqlecom = "UPDATE do_order set in_transit='".$status.
    "',tconformed_by='Ecom' where tracking_id=".$orderid;
    $db_handleecom = new DBController();
    $resultecom = $db_handleecom - > executeUpdate($sqlecom);
  }

  // store the responce in array 
  $response[$orderid] = $status;
}
echo json_encode($response);

请帮我找到解决方案,我正在使用mysqli ....

如果您有任何疑问,请告诉我....在此先感谢。

更新

在我获取基于orderid而不是awb的状态值之前,您可以在上面的图像中看到,在刷新页面之前显示时间状态。这是根据订单ID获取状态的代码....

$curl_data['username']='admin'; 
$curl_data['password']='admin123'; 


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

foreach($data as $id){ 

$orderid = $id; 
$curl_data['awb']=$orderid; 

$hide = '';
 $url = 'https://plapi.ecomexpress.in/track_me/api/mawbd/?awb=awbnumber&order='.$orderid.'&username=admin&password=admin123'; 
$ch = curl_init(); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_data); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 


$output = curl_exec ($ch); 
curl_close($ch); 
$res = explode("\n",$output); 

if ( ! isset($res[13])) 
{ 
$res[13] = null; 
} 



$status = str_replace('</field>','',$res[13]); 



$statusfinal = str_replace('<field type="CharField" name="status">','',$status); 
if($statusfinal!='') 
{ 
$sqlecom = "UPDATE do_order set in_transit='".$statusfinal."',tconformed_by='Ecom' where order_id=".$orderid; 
$db_handleecom = new DBController(); 
$resultecom = $db_handleecom->executeUpdate($sqlecom); 
} 

// store the responce in array 


$response[$orderid] = $statusfinal; 

}
echo json_encode($response);

更新2

网络标签下方,我已正确回复https://pastebin.com/VpWsngnV

0 个答案:

没有答案