即使我的process.php有效,data.success
也会返回false。我一直在尝试调试它,但我找不到导致此错误的错误。
显示“OKAY!”仅当我将data.success
更改为!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>');
}
})
});
});
});
有人可以帮忙吗?
答案 0 :(得分:1)
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>');
}
});