0

以下登录脚本在 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();
    }
});

};

万分感谢!

4

1 回答 1

0

似乎您的表单是正常提交​​的,而不是使用 ajax,如果是这样,请尝试:

.....
$('#submitOne').click(function(e) {
    if (e.preventDefault) { 
       e.preventDefault(); 
    } 
    else { e.returnValue = false; } 
    //rest of your code
于 2012-07-27T05:44:43.203 回答