HEEEP! There is an html form and a file in which the request to the database occurs by pressing a button. How can I make the request happen without reloading the page?

<form action="" method="post"> <input id="street" name="street" type="text" required="" placeholder="НазваниС ΡƒΠ»ΠΈΡ†Ρ‹" autocomplete="off" class="suggestions-input" style="box-sizing: border-box;"> <input id="house" name="house" type="text" required="" placeholder="НомСр Π΄ΠΎΠΌΠ°" autocomplete="off" class="suggestions-input" style="box-sizing: border-box;"> <input type="submit" class="button" value="ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ"> </form> <?php $host = '*******'; $user = '*******'; $pass = '*****'; $db_name = '******'; $link = mysqli_connect($host, $user, $pass, $db_name); if (!$link) { echo 'НС ΠΌΠΎΠ³Ρƒ ΡΠΎΠ΅Π΄ΠΈΠ½ΠΈΡ‚ΡŒΡΡ с Π‘Π”. Код ошибки: ' . mysqli_connect_errno() . ', ошибка: ' . mysqli_connect_error(); exit; } if(isset($_POST['smb'])) { mysqli_set_charset($link, 'utf8'); $a=0; $street= $_POST['street']; $house = $_POST['house']; $sql = mysqli_query($link, 'SELECT * FROM test'); while ($result = mysqli_fetch_array($sql)) { if (($result['street']==$street)&&($result['house']==$house)){ $a=$a+1;} } if ($a>0) {echo "ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ.";} else {echo "ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ Π½Π΅Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ.";} } ?> 

    1 answer 1

    Get the value of a form element through document.getElementById ('i_input'). Value and send the form via an AJAX request. Request example:

     $.ajax({ type: 'POST', url: 'response.php?action=sample2', data: 'name=Andrew&nickname=Aramis', success: function(data){ $('.results').html(data); } });