我的jquery移动登录提交无法正常工作
我的jquery代码如下......这里是jsfiddle http://jsfiddle.net/dD6Dg/
$('#loginform').submit(function (e) {
alert("loggg");
e.preventDefault();
$.ajax({
type: "POST",
url: '/class/login.php',
data: $(this).serialize(),
success: function (data) {
if (data === 'Login') {
window.location = '/user-page.php';
}
else {
alert('Invalid Credentials');
}
}
});
});
答案 0 :(得分:3)
使用click
事件代替submit
,因为代码中没有提交按钮。您正在使用a
标记,因为您需要使用click
事件而不是submit
$('#loginform').click(function(e) {
alert("loggg");
e.preventDefault();
$.ajax({
type: "POST",
url: '/class/login.php',
data: $(this).serialize(),
success: function(data)
{
if (data === 'Login') {
window.location = '/user-page.php';
}
else {
alert('Invalid Credentials');
}
}
});
});