Hello to all! Tell me how you can implement this on JS:
There is a form, after pressing a key of which, JavaScript should execute a php script that is located in includes / check.php without reloading the page and get the execution result from it ( true or false ). Accordingly, if it is true , we deduce that everything is fine, if false - the alert
window with the text of the error (say, just the "Error") and all this should be without reloading the page.
UPD. As I understand it, I just do not send an Ajax request. I cite my code:
JS and form:
<script> //Check Invite $("#reg").click(function() { // получаем то, что ввёл пользователь var checkString = $(".invite").val(); // формируем строку запроса var data = 'invite='+ checkString; // если checkString не пуста $.ajax({ type: "POST", url: 'includes/checkInvite.php', data: data, success: function(data){ if(data === true){ alert("good"); } else { alert("false"); } }); }); </script> <form method="POST"> <input type="hidden" name="posted2" /> <input type="text" name="invite" title="Что бы стать участником, нужно иметь инвайт (приглашение)" class="text_box invite" placeholder="Ваш инвайт"/> <input type="submit" value="Регистрация" class="button" style="margin: 0 auto; display: block" id="reg"/> </form>
As well as the file checkInvite.php:
<?php session_start(); if(isset($_GET[invite]) && strlen($_GET[invite]) == 30){ //проверяем длину инвайта require_once 'classes/class.DB.php'; require_once 'classes/class.glob.php'; $objDB = new DB(); $objGlob = new Glob(); $query = $objDB->QuerySelect('*', 'invites', "invite = '$_POST[invite]'"); $myrow = mysql_fetch_assoc($query); //фетчим массив if($myrow[status] == 'active'){ //проверяем статус инвайта echo "true"; } else { //если инвайт уже использовался echo "false"; } } else { //если инвайт-строка не равна 30! echo "false"; } ?>