简体   繁体   中英

jQuery AJAX request won't work in Internet Explorer

I have an ajax login on my site and for some strange reason, it won't work in internet explorer yet it works in Webkit, latest version of FireFox, and Opera. So I don't think it is my code but is there a known problem with ajax requests for IE? Thanks!


Javascript:

$('.mainlogin').submit(function() {
    var username = $('#main_username').val();
    var password = $('#main_pword').val();
    $.ajax({
        url: 'log.php',
        type: 'POST',
        data: {
            user: username,
            pass: password
        },
        success: function(response) {
            if (response == 'success') {
                window.location.reload();
            } else {
                $('.logerror').fadeIn(250);
            }
        }
    });
    return false;
});

PHP:

<?php 
require_once('.conf.php');
$user = mysql_real_escape_string($_POST['user']);
$pass = mysql_real_escape_string($_POST['pass']);

$result = mysql_query("SELECT * FROM accountController WHERE username = '$user'");
    while ($row = mysql_fetch_array($result)) {
        if (sha1($user.$pass) == $row['pword']) {
            session_start();
            $_SESSION['login'] = 1;
            $_SESSION['uname'] = $row['username'];
            $_SESSION['id'] = $row['id'];
            echo "success";
        } 
    }    
?>

@"IE8, IE9 works around 25% of the time."

Becuase IE8:

"uses the first session cookie set and not the last as in Firefox."
http://anvilstudios.co.za/blog/php/session-cookies-faulty-in-ie8/

To fix this problem all you need to do is set:

session_regenerate_id(true);

Which deletes old session id and forces IE8 to use the new one.

@FAIL:

Caching may be the problem, try adding:

cache: false,

@FAIL2:

success: function(response) {
            if (response == 'success') {

                 document.getElementById('status').innerHTML=http.responseText;
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM