S
S
Snatch082021-05-06 23:15:06
AJAX
Snatch08, 2021-05-06 23:15:06

How to display data from the database using server-side js?

Good day everyone! Now I'm pulling data from the database using Ajax and PHP like this:

let Howaquou = '';

$.ajax({
  url: 'скрипт.php',
  method: 'POST',
  dataType: 'json',
  data: {'type' : 'pack'},
  success: function(Buqhou){

    for(let Beou = 0; Beou <= Buqhou.length - 1; Beou++){

    Howaquou += '<div class="Noenex">' +

    '<img src="' + window.location + 'img/' + Buqhou[Beou].RepackCode + '/' + Buqhou[Beou].Cover + '" />' +

    '</div>';

    document.getElementsByClassName('Deff')[0].innerHTML = Howaquou;
    }
  }
});


@include($_SERVER['DOCUMENT_ROOT'] . '/bd.php');


if(isset($_POST)){

  $type = trim($_POST['type']);

  $result = "SELECT * FROM `$type` WHERE `Play` = '123'";
  $query = @mysqli_query($connect, $result) or die(mysqli_error());

  while($row = mysqli_fetch_assoc($query)){
    $array[] = $row;
  };

  $json = defined('JSON_UNESCAPED_UNICODE')
    ? json_encode($array, JSON_UNESCAPED_UNICODE)
    : json_encode($array);
  echo $json;
}


Can you please tell me how to display the same using server js? For example, through Node js. I understand how regular js works, but I don't understand how server-side js works at all.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question