用户登录后将立即提交用户表单
A user form will be submitted as soon as the user logged in
我是 AJAX 的新人。我正在开发一个网站,用户可以在其中 post 了解有关该项目的详细信息。用户可以在不登录的情况下将数据插入表单,但是当用户单击 submit
时,AJAX 脚本将检查用户会话是否存在,如果不存在,将显示登录模式。
我想在这里说的是,一旦用户登录,项目表单将立即自动提交 AJAX。
我是这样做的,当用户点击项目表单提交脚本检查用户会话时,如果会话不存在,登录模式将通过 AJAX 出现,我设置了一个 JavaScript 计时器在一定时间间隔后将检查用户是否仍然登录。
这是我的jQuery脚本
$(function() {
$('form').on('submit', function(e) {
e.preventDefault();
$.ajax({
url: 'ajxprocess/checksignin.php',
success: function(result) {
if (result == '0') {
$.ajax({
cache: false,
url: 'ajxload/signin_gl.php',
success: function(result) {
$('#static').modal('show');
$('#static').html(result);
var myTimer = setInterval(function() {
checksignin()
}, 500);
}
});
} else {
$.ajax({
type: 'post',
url: 'ajxprocess/finalprocess.php',
data: $('form').serialize(),
beforeSend: function() {
$('#final').html("<img src='assets/img/input-spinner.gif' />");
},
success: function(html) {
if (html == '1') {
window.location = 'posts.php';
} else {
$('#final').html('Somthing went wrong during the process!');
}
}
});
}
}
});
});
});
这是我的登录检查器
function checksignin() {
$.ajax({
url: 'ajxprocess/checksignin.php',
success: function(result) {
if (result !== '0') {
$.ajax({
type: 'post',
url: 'ajxprocess/finalprocess.php',
data: $('form').serialize(),
beforeSend: function() {
$('#final').html("<img src='assets/img/input-spinner.gif' />");
},
success: function(html) {
if (html == '1') {
window.location = 'posts.php';
} else {
$('#final').html('Error occured during the process!');
}
}
});
}
}
});
}
问题是我不想使用计时器。还有其他流程吗?
你有 login
ajax 的成功和错误函数,如果成功你可以提交表单,错误时做其他事情。直到那时你可以显示一个加载符号。这样你就不需要使用计时器了。
我是 AJAX 的新人。我正在开发一个网站,用户可以在其中 post 了解有关该项目的详细信息。用户可以在不登录的情况下将数据插入表单,但是当用户单击 submit
时,AJAX 脚本将检查用户会话是否存在,如果不存在,将显示登录模式。
我想在这里说的是,一旦用户登录,项目表单将立即自动提交 AJAX。
我是这样做的,当用户点击项目表单提交脚本检查用户会话时,如果会话不存在,登录模式将通过 AJAX 出现,我设置了一个 JavaScript 计时器在一定时间间隔后将检查用户是否仍然登录。
这是我的jQuery脚本
$(function() {
$('form').on('submit', function(e) {
e.preventDefault();
$.ajax({
url: 'ajxprocess/checksignin.php',
success: function(result) {
if (result == '0') {
$.ajax({
cache: false,
url: 'ajxload/signin_gl.php',
success: function(result) {
$('#static').modal('show');
$('#static').html(result);
var myTimer = setInterval(function() {
checksignin()
}, 500);
}
});
} else {
$.ajax({
type: 'post',
url: 'ajxprocess/finalprocess.php',
data: $('form').serialize(),
beforeSend: function() {
$('#final').html("<img src='assets/img/input-spinner.gif' />");
},
success: function(html) {
if (html == '1') {
window.location = 'posts.php';
} else {
$('#final').html('Somthing went wrong during the process!');
}
}
});
}
}
});
});
});
这是我的登录检查器
function checksignin() {
$.ajax({
url: 'ajxprocess/checksignin.php',
success: function(result) {
if (result !== '0') {
$.ajax({
type: 'post',
url: 'ajxprocess/finalprocess.php',
data: $('form').serialize(),
beforeSend: function() {
$('#final').html("<img src='assets/img/input-spinner.gif' />");
},
success: function(html) {
if (html == '1') {
window.location = 'posts.php';
} else {
$('#final').html('Error occured during the process!');
}
}
});
}
}
});
}
问题是我不想使用计时器。还有其他流程吗?
你有 login
ajax 的成功和错误函数,如果成功你可以提交表单,错误时做其他事情。直到那时你可以显示一个加载符号。这样你就不需要使用计时器了。