2012-07-27 148 views
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(); 
    } 
}); 

}; 

謝謝!

+2

如果'e.preventDefault();'並不妨礙形式從提交嘗試'返回false ;' – Musa 2012-07-27 05:12:00

回答

0

看來你的形式與阿賈克斯正常,未提交,如果多數民衆贊成的情況下,然後嘗試:

..... 
$('#submitOne').click(function(e) { 
    if (e.preventDefault) { 
     e.preventDefault(); 
    } 
    else { e.returnValue = false; } 
    //rest of your code 
+0

它仍然帶我到login.php顯示文本:「{」error「:false,」msg「:」「 歡迎來到jeremy! <\/h3>「}」 – Jeremythuff 2012-07-27 21:33:42