Встретился с проблемой, что не работает "success", сам ajax вроде работает, данные отправляются на обработчик.
javascript:
function RunAjax(){
var login1 = $(".login").val();
var password1= $(".password").val();
var blog_name = $(".blog_name").val();
var description = $(".description").val();
$.ajax({
type: 'POST',
data: {log:login1, pass:password1, blog:blog_name,desc:description},
url:'php/Register.php',
dataType:'json',
success: function()
{
alert("Success");
//var tex = data.mes;
//$(".AjaxAnswer").val(data.mes);
//console.log(data.mes);
//document.getElementById('AjaxAnswer').innerHTML = data.mes;
},
});
}
$(".button").click(RunAjax);
PHP:
$message = array();
if ($query > 0){
$message['mes'] = "Login zanyat";
//echo json_encode($message);
}
elseif (!preg_match('|^[A-Z0-9]+$|i', $login)){
$message['mes'] = "Your username should consist only of the Latin alphabet";
//echo json_encode($message);
}
elseif (!preg_match('|^[A-Z0-9]+$|i', $password)){
$message['mes'] = "Your password should consist only of the Latin alphabet";
//echo json_encode($message);
}
elseif (!preg_match('|^[A-Z0-9]+$|i', $blog_name)){
$message['mes'] = "Your blog name should consist only of the Latin alphabet";
//echo json_encode($message);
}
else {
$sql = mysql_query('INSERT INTO Users(Login,Password,Blog_name,Description) VALUES("'.$login.'","'.md5($password).'","'.$blog_name.'","'.$description.'")');
$message['mes'] = "Registration succses";
//echo json_encode($message);
}
echo json_encode($message);
HTML:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<script type="text/javascript" src = "java_css/java.js"></script>
<link rel="stylesheet" type="text/css" href = "java_css/style.css">
<head>
<body>
<div align = "center" id ="form">
Login:<br>
<input type = "text" name = "login" required class = "login"><br>
Password:<br>
<input type = "password" name = "password" required class = "password">
<br>
Enter a name for your blog:<br>
<input type = "text" name = "blog_name" required class = "blog_name"><br>
Brief description of:<br>
<input type = "text" name = "description" required class = "description"><br>
<input type = "button" value = "Click me, if you ready end this path" id = "button">
<br>
</div>
<div>
<p class = "AjaxAnswer"></p>
</div>
</body>
</html>