0
以下登錄腳本在Internet Explorer中不起作用。它關心我login.php並返回錯誤/成功消息,而不是在原始頁面上。任何解釋或解決這個問題將不勝感激。Jquery .ajax在ie中不工作
//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();
}
});
};
謝謝!
如果'e.preventDefault();'並不妨礙形式從提交嘗試'返回false ;' – Musa 2012-07-27 05:12:00