以下登录脚本在Internet Explorer中不起作用。它是关心login.php并在那里返回错误/成功消息,而不是在原始页面上。任何解释或解决这个问题将不胜感激。
//ajax login
$(document).ready(function() {
$('#result').hide();
$('#submitOne').click(function(e) {
e.preventDefault();
var errors = '';
var required = ' is required';
var username = $('form #username').val();
var password = $('form #password').val();
if (username == '') {
errors += '<p> A username' + required + '</p>';
}
if (password == '') {
errors += '<p> A password' + required + '</p>';
}
if (errors !== '') {
$('form #result').removeClass().addClass('error').html('<strong>Please correct the errors below.</strong>' + errors).fadeIn('slow');
}
else {
$('form #result').removeClass().addClass('loading').html('<strong>Working...</strong>').fadeIn('slow');
var formData = $('form').serialize();
submitForm(formData);
}
});
});
function submitForm(formData)
{
$.ajax
({
type: 'POST',
url: 'login.php',
data: formData,
dataType: 'json',
cache: false,
timeout: 10000,
success: function(data)
{
$('form #result').removeClass().addClass((data.error === true) ? 'error' : 'success').html(data.msg).fadeIn('slow');
if($('form #result').hasClass('success'))
{
setTimeout("window.location.replace('admin.php')", 2000);
}
},
error: function(XMLhttpRequest, textStatus, errorThrown)
{
$('form #result').removeClass().addClass('error')
.html('<p>There was a <strong> ' + errorThrown + ' </strong> error due to a <strong>' + textStatus + '</strong> condition </p>').fadeIn('slow');
},
complete: function(XMLhttpRequest, status)
{
$('form')[0].reset();
}
});
};
非常感谢!
答案 0 :(得分:0)
似乎您的表单是正常提交的,而不是使用ajax,如果是这样的话,请尝试:
.....
$('#submitOne').click(function(e) {
if (e.preventDefault) {
e.preventDefault();
}
else { e.returnValue = false; }
//rest of your code