Несмотря на то, что мой process.php работает, data.success
возвращает false. Я пытался его отладить, но я не смог найти ошибку, вызвавшую это.
Он показывает "OKAY!" сообщение только если я изменю data.success
to !data.success
, почему?
HTML
<form id="my" action="" method="post">
<label for="name">Name</label>
<input type="text" id="name" name="name" value="<?php echo $name; ?>">
<label for="surname">Surname</label>
<input type="text" id="surname" name="surname" value="<?php echo $surname; ?>">
<label for="username">Username</label>
<input type="text" id="username" name="username" value="<?php echo $username; ?>">
<label for="email">Email</label>
<input type="text" id="email" name="email" value="<?php echo $user_email; ?>">
<input id="save" type="submit" name="changeit" value="Save Changes">
</form>
JQuery
$(document).ready(function () {
$(function () {
$('#my').submit(function (e) {
e.preventDefault();
var form = $(this);
var formData = form.serialize();
$.ajax({
type: 'POST',
url: '/modules/settings/process.php', // the url where we want to POST
data: formData // our data object
}).done(function (data) {
if (data.success) {
$('#my').append('<div class="alert alert-success">' + "OKAY!." + '</div>');
}
})
});
});
});
Может ли кто-нибудь помочь?
action=""
из заголовка form
, меньше - больше попробуйте этот код для части ajax
$.ajax({url: '/modules/settings/process.php', type: 'post', data: $('form').serialize(), success: function(data){
$('#my').append('<div class="alert alert-success">' + "OKAY!." + '</div>');
}
});