我正在尝试在不刷新页面的情况下提交此表单,但是当我提交时,它会将我带到操作页面。我的代码有什么问题?这是我的表格:
<form class="ajax" action="/../addchannel/createUser.php" method="post" >
<input type="text" name="userName" placeholder="userName"><br>
<input type="text" name="email" placeholder="email"><br>
<input type="submit" value="submit" >
</form>';
这是我的脚本:
$('form.ajax').on('submit', function () {
var that = $(this),
url = that.attr('action'),
type = that.attr('method'),
data = {};
that.find(['name']).each(function (index, value)) {
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
});
$.ajax({
url: url,
type: type,
data: data,
success: function (response) {
consol.log(response)
}
});
});