Home>
$(function () {
  $("# send"). on ('click', function () {
    var ary_data = {};
    ary_data.userid = $('input [name = "id"]'). val ();
        ary_data.product = $('input [name = "product"]'). val ();
        ary_data.color = $('input [name = "color"]'). val ();
        send_data = JSON.stringify (ary_data);
    $.ajax ({
    type: "POST",
    url: ". send.php",
        dataType: "json",
        data: send_data,
        cache: false,
        processData: false,
    contentType: false,
    }). done (function (data) {
                 data.forEach (function (x) {
                         Object.entries (x) .forEach (y =>{
                             $("# res"). append ('key:' + y [0] + ': value:' + y [1] + "<br/>");
                         });
                     });
         }). fail (function (XMLHttpRequest, textStatus, errorThrown) {
             alert (errorThrown);
         });
     });
 });
<? php
$json = file_get_contents ("php: // input");
$json_data = json_decode ($json, true);
$ID = $json_data ['userid'];
$product = $json_data ['product'];
$color = $json_data ['color'];
$str = "ID = {$ID}, product = {$product}, color = {$gcolor}";
$fp = fopen ("product.txt", "a");
   fwrite ($fp, $str. PHP_EOL);
   fclose ($fp);
   $fp = fopen ("product.txt", "r");
   while (($data = fgetcsv ($fp, 1024))! == false) {
     $tmp =&$datas [];
     foreach ($data as $x) {
       $y = explode ("=", $x);
       $tmp [trim ($y [0])] = trim ($y [1]);
     }
   }
   unset ($tmp);
   fclose ($fp);
   $data = json_encode ($datas);
   echo $data;

I send data with post and register it in a txt file
Input to txt file is properly id = 1, product = pen, color = red
id = 2, product = pen, color = green
You can register as well, but if you try to display this in js
Key: ID: Value: 1
Key: product: value: pen
Key: color: value: red
Key: ID: Value: 2
Key: product: value: pen
Key: color: value: green
Key: ID: Value: 1
Key: product: value: pen
Key: color: value: red
Key: ID: Value: 2
Key: product: value: pen
Key: color: value: green
Key: ID: Value: 3
Key: product: value: pen
Key: color: Value: black
It will be displayed in addition to the previous display. How can I erase it?