Не могу понять почему возвращает пустую строку а не echo "success"
код JS
function submitForm(){
var category = $("#commentCategory").val();
var nickname = $("#commentNickname").val();
var message = $("#commentMessage").val();
var email = $("#commentEmail").val();
var title = $("#commentTitle").val();
$.ajax({
type: "POST",
url: "includes/commentprocess.php",
data: "category=" + category + "&nickname=" + nickname + "&comment=" + message +"&email=" + email + "&title=" + title, //$(this).serialize(),
success : function(text){
if (text == "success"){
formSuccess();
console.log('b');
} else {
formError();
submitMSG(false,text);
console.log(text);
}
}
});
}
PHP
<?php
$errorMSG = "";
if(!empty($_POST['commentsubmit'])){
$category = $_POST['commentCategory'];
$nick = $_POST['commentNickname'];
$commessage = $_POST['commentMessage'];
$email = $_POST['commentEmail'];
$title = $_POST['commentTitle'];
if ($title == '' OR $nick == '' OR $email == '' OR $category == '' OR $commessage == '')
{
$errorMSG = "Заполните поля";
exit();
}
else
{
$user=R::dispense( 'comments' );
$user->category = $category;
$user->nickname = $nick;
$user->comment = $commessage;
$user->email = $email;
$user->title = $title;
R::store($user);
if ($errorMSG == "") {
echo "success";
}
}
}
?>
подключение осуществляется RedBeanom. Новичек в этой теме.
пример поля form
<form role="form" id="commentForm" data-toggle="validator" method="POST">
<div class="row">
<div class="form-group col-sm-6">
<label for="commentTitle" class="h4">Тема</label>
<input type="text" class="form-control" id="commentTitle" placeholder="Тема" required>
<div class="help-block with-errors"></div>
</div>