如何在几秒钟后通过纯javascript将多条记录中的一条一条发送到php

如何在几秒钟后通过纯javascript将多条记录中的一条一条发送到php,javascript,php,Javascript,Php,我最近购买了一个whats应用程序API,所以我想与我的web应用程序结合,一切都很好 但我想在几秒钟后逐个发送多个记录,例如,每个记录在30秒后发送到whatsapp.php 这是我的HTML表单 <label class="container22"> <div style="margin-left: 50px;"> <div>InvoiceID: 1 </div&

我最近购买了一个whats应用程序API,所以我想与我的web应用程序结合,一切都很好

但我想在几秒钟后逐个发送多个记录,例如,每个记录在30秒后发送到whatsapp.php

这是我的HTML表单

    <label class="container22">
        <div style="margin-left: 50px;">
            <div>InvoiceID: 1 </div>

          <input class="checkbox_inputs" type="checkbox" name="sending" class="Sending_JS" value="<?php echo $Info->MobNum1; ?>" data-u-mobile="<?php echo $Info->MobNum1; ?>"/>

          <input type="hidden" name="phone" value="252634638883">

          <span class="checkmark"></span>
      </div>
    </label>



    <label class="container22">
        <div style="margin-left: 50px;">
            <div>InvoiceID: 2 </div>

          <input class="checkbox_inputs" type="checkbox" name="sending" class="Sending_JS" value="<?php echo $Info->MobNum1; ?>" data-u-mobile="<?php echo $Info->MobNum1; ?>"/>

          <input type="hidden" name="phone" value="252634638884">

          <span class="checkmark"></span>
      </div>
    </label>



    <label class="container22">
        <div style="margin-left: 50px;">
            <div>InvoiceID: 3 </div>

          <input class="checkbox_inputs" type="checkbox" name="sending" class="Sending_JS" value="<?php echo $Info->MobNum1; ?>" data-u-mobile="<?php echo $Info->MobNum1; ?>"/>

          <input type="hidden" name="phone" value="252634638885">

          <span class="checkmark"></span>
      </div>
    </label>

    <button id="submit_input" type="submit" name="submit" value="Send" style="width: 100%; height: 100%; cursor: pointer; font-size: 22px; background-color: #DD6739; color: white; border: 0;">Send</button>

发票编号:1

试着对sameIf使用debounce方法如果这是你的真实身份验证令牌,你会想改变它…devajay我怎么办,能用codingAlex hoansky解释我吗,身份验证令牌过期了有人帮我解决问题吗?
let submit_input        = document.getElementById('submit_input');
let InternationalKey_JS = document.getElementById('InternationalKey_JS');

let Sending_JS          = document.getElementsByClassName('Sending_JS');
let Sending_JS_length   = Sending_JS.length;

let container22        = document.getElementsByClassName('container22');
let container22_Length = container22.length;





submit_input.addEventListener('click', function(){
    const checkbox = document.querySelectorAll('input:checked');

    if(checkbox.length === 0) {
        alert('madhan dhamaan');
    }

    else {

        for (var i = 0; i < checkbox.length; i++) {
            let MobNum = checkbox[i].getAttribute('data-u-mobile');

            console.log(MobNum);

            //setInterval(function(){
                
                let data       = "phone=" + MobNum;
                let SendingURL = "WhatsappController.php";

                let xhttp;
                xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function() {
                  if (this.readyState == 4 && this.status == 200) {
                        let NewTicketResult = xhttp.responseText.replace(/"/g,"");
                        let myOBJ           = JSON.parse(xhttp.responseText);

                        //QtyJS.value             = myOBJ.Quantity;
                        //TotalAmountUSD_JS.value = myOBJ.TotalAmountUSD;   

                  }
                };

                xhttp.open("POST", SendingURL, true);
                xhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                xhttp.send(data);

            //}, 10000);

        } // End for loop

        //console.log(checkbox.length + ' checkbox checked');

    } // End else

}); // End submit_input
    <?php 

header("Content-Type: application/json; charset=UTF-8");
require_once 'config/config.php';



if(empty($_POST['phone'])) {
  echo 'sending filed is empty';
}

else {
  $Phone            = $_POST['phone'];
  $InternationalKey = 252;
  $Phone_With_Code  = $InternationalKey . $Phone;
  //echo json_encode($Phone_With_Code);

  $Text = 'Hello, This is a text message from my phone number';

  $data = [
    'phone' => $Phone_With_Code, // Receivers phone
    'body' => $Text, // Message
  ];

  $json = json_encode($data); // Encode data to JSON
  // URL for request POST /message
  $url = 'https://eu174.chat-api.com/instance166887/message?token=f5d7usipaxxwqqzu';
  // Make a POST request
  $options = stream_context_create(['http' => [
          'method'  => 'POST',
          'header'  => 'Content-type: application/json',
          'content' => $json
      ]
  ]);

  // Send a request
  $result = file_get_contents($url, false, $options);
  //print_r($result);
  echo json_encode($result);

}

?>