如何在php中刷新字符串

时间:2018-10-15 02:26:55

标签: php ajax

我编写了此代码以在PHP中制作多个页面

if ($_GET['action'] == 'go_depo') {
   function loadStatus(){
    if($json->data->pending_received_balance != '0'){
    $checkaddr = $block_io->get_transactions(array('type' => 'received', 'before_tx' => '', 'addresses' => $getaddr->data->address));
    if($checkaddr->data->txs[0]->amounts_received[0]->amount){
        if($checkaddr->data->txs[0]->amounts_received[0]->amount <= $amounthyips){
            $checkadr = '<strong>Order Status:</strong> Your payment amount is less than $166. Please contact admin for more information';
        }else{
            if($checkaddr->data->txs[0]->txid){
                $checkadr = '<span class="text-success">Payment Completed</span> TXID: <a href="https://dogechain.info/tx/'.$checkaddr->data->txs[0]->txid.'" target="_blank">'.$checkaddr->data->txs[0]->txid.'</a>';
            }else{
                $checkadr = '<strong>Order Status:</strong> Waiting for payment';
            }
        }
    }else{
    $checkadr = '<strong>Order Status:</strong> Waiting for payment';
    }
    }else{
    echo 'kosong';
    }
   }
}

如何获取成功更改值$?来自ajax还是什么?没有刷新页面?

所以功能是获取间隔刷新内容并找到成功字符串的更改值

===================================== 编辑我的代码,我希望通过jquery或html中的javascript函数每隔10秒更新一次loadStatus函数,而无需刷新页面

1 个答案:

答案 0 :(得分:0)

您可以使用javascript AJAX调用和setInterval()方法执行此操作,如下所示:

<script type="text/javascript">
setInterval ( function ()
{
  var xmlhttp;
  // First, check if XMLHttpRequest exist at window object (IE 7+, Firefox, Chrome, Opera and Safari
  if ( window.XMLHttpRequest)
  {
    xmlhttp = new XMLHttpRequest ();
  } else {
    // Otherwise, it's IE <7
    xmlhttp = new ActiveXObject ( 'Microsoft.XMLHTTP');
  }
  xmlhttp.onreadystatechange = function ()
  {
    if ( xmlhttp.readyState == 4 && xmlhttp.status == 200)
    {
      document.getElementById ( 'refresh_div').innerHTML = xmlhttp.responseText;
    }
  }
  xmlhttp.open ( 'POST', 'youscript.php?action=go_depo', true);
  xmlhttp.send ();
}, 10000);
</script>

注意:我正在调用 yourscript.php ,您需要在open()方法上进行更改。此外,该脚本的结果还将在页面上的

元素处替换为 id = refresh_div