简体   繁体   中英

jQuery Functions Does Not Work in IE7

I am currently working on this small AJAX news letter signup form to allow users to subscribe to a mailing list. Although this works on almost all browsers, it does not work on IE7 and below. I was wondering if there is something wrong with my source code, or that theres is an alternative method of doing the same functions, just in pure javascript?

Below is my javascript:

$(document).ready(function(){
/* Form Appear Effect */
$('#exists').hide();
$("#formParts").hide();
$("#thanks").hide();
$("#wait").hide();

$('#exists').css({"visibility":"hidden"});


$('#email').click(function() {
    $('#formParts').slideDown();
});

/* AJAX Form Submission */
$('#submitButton').click(function () {
    //Reset Form
    $('.blogSignUp').css('border', '1px solid #E6E6E6');
    $('.blogSignUp').attr('enabled','true');

    // Extract Variable
    var firstName = $('#firstName').val();
    var lastName = $('#lastName').val();
    var email = $('#email').val();

    // Check for Blank Bields
    if (firstName == "" || lastName == "" || email == "") {
        if (email == "")
            $('#email').css('border', '1px solid #E42217');
        if (firstName == "")
            $('#firstName').css('border', '1px solid #E42217');
        if (lastName == "")
            $('#lastName').css('border', '1px solid #E42217');
        return false;
    } else {

        // Check Email
        if (echeck(email) == false) {
            $('#email').css('border', '1px solid #E42217');
            return false;
        } else {
            // Disable and Hide Forms for now...
            $('#formParts').slideUp ();
            $('#form').slideUp();
            $('#exists').fadeOut();

            // Show processing message...
            $("#wait").fadeIn();    

            var data = $('#signup').serialize();

            // Show processing message...
            $("#wait").fadeIn();

            $.ajax({
                type: 'POST',
                url: '../signup.php',
                data: {
                    action: 'signupFunction',
                    firstName: firstName,
                    lastName: lastName,
                    email: email,
                },
                error: function(MLHttpRequest, textStatus, errorThrown) {
                    alert(errorThrown);
                },
                success: function(result, status) {
                    //alert(result);
                    if (result == "Good") {
                        $("#exists").fadeOut();
                        $("#wait").fadeOut();
                        $("#thanks").fadeIn();
                    }
                    if (result == "Exists") {
                        $('.blogSignUp').css('border', '1px solid #E6E6E6');                    
                        $('#email').css('border', '1px solid #E42217');
                        $("#wait").fadeOut();
                        $("#exists").fadeIn();
                        $('#formParts').slideDown();
                        $('#form').slideDown();
                        return false;
                    }
                }
            });
        }
    }      
}); }); function echeck(str) {

    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
       return false
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
       return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        return false
    }

     if (str.indexOf(at,(lat+1))!=-1){
        return false
     }

     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        return false
     }

     if (str.indexOf(dot,(lat+2))==-1){
        return false
     }

     if (str.indexOf(" ")!=-1){
        return false
     }

     return true                    }

Thank you very much in advanced.

data: {
                action: 'signupFunction',
                firstName: firstName,
                lastName: lastName,
                email: email,
            }

should be

data: {
                action: 'signupFunction',
                firstName: firstName,
                lastName: lastName,
                email: email
            },

IE breaks when commas are inserted to the last variable of an array, firefox doesnt.

Assuming your code is error free, you can always do a hard-coded work-around for IE7.

JQuery Browser Detection

User jQuery to detect what browser the user is using, and create a condition that states if they're in IE7, do this _ __ _ __ _ __ etc. etc. If your current problem is html/css related, it's usually very simple to make a ie7 patch.

(If you're wondering 'why IE7?' save yourself the time and stop. The browser is notorious for causing developers issues, especially with jQuery. Chances are it's not your fault, it's the browser's.)

Hey i think the only problem is

Problem at line 62 character 33: Extra comma.
email: email,

Also try to use JSLINT to check your code for errors. IE is very specific to these mistakes.

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