The error in the ajax request always displays the contents (data == '1'), that is, it says that the data is not transmitted itself. The ajax request is triggered; the page does not reload; help 2 day I suffer
$(document).ready(function() { $("#clickButtonForm").bind("click", function () { $.ajax ({ url: "ajax.php", type: "POST", data: {login: $("#login").val(), password: $("#password").val(), email: $("#email").val()}, dataType: "html", beforeSend: function (){ $("#information").text ("Expectaton data...") }, success: function (data){ // в случае, когда пришло success. Отработало без ошибок if (data == '0') $("#error").text("Occured error speak administraor").removeClass("error").addClass("success").show().delay(8000).fadeOut(3000); // $("#error").text("You success registration").removeClass("error").addClass("success").show().delay(3000).fadeOut(3000); // в случа ошибок else (data == '1') $("#error").text("Occured error speak administraor").removeClass("success").addClass("error").show().delay(8000).fadeOut(3000); } }); }); });
here is the html template
<form role="form" class="formForMe" id="register_form" method="post"> <div class="input-group"> <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span> <input type="text" class="input form-control" id="login" placeholder="Введите Ваш будующий логин для входа" required autofocus /> </div> <div class="input-group"> <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span> <input type="password" id="password" class="input form-control" placeholder="Введите Ваш пароль для входа" required /> </div> <div class="input-group"> <span class="input-group-addon"><span class="add-on">@</span></span> <input type="text" class="input form-control" id="email" placeholder="Ваш существующий email" required autofocus /> </div> <div class="row"> <div class="col-xs-6 col-sm-6 col-md-6 col-lg-12"> </div> <div class="col-xs-6 col-sm-6 col-md-6 col-lg-12"> <button type="button" class="clickButtonForm btn btn-labeled btn-success" id="clickButtonForm"> <span class="btn-label"><i class="glyphicon glyphicon-ok"></i></span>Войти</button> <button onclick="location.href='../index.html'" type="submit" class="btn btn-labeled btn-danger"> <span class="btn-label"><i class="glyphicon glyphicon-remove"></i></span>Назад</button> </div> </div> <p> <a href="#">Забыли свой пароль?</a></p> </form>
and php handler ajax.php
<?php if(isset(($_POST['login'], $_POST['password'], $_POST['email'])) { echo 0; } else { echo 1; } ?>
else (data == '1')
. It seems you forgot to add a couple of letters and a space. - Pavel Mayorovif(isset($_POST['login'], $_POST['password'], $_POST['email'])) {
- Ivan Pshenitsynelse
always goes block{ ... }
.else
- "then" - does not imply any conditions like yours. And you need to addif
to getelse if(...){ ... }
.тогда если (условие){действия}
- Ivan Pshenitsyn