但不是在Firefox和IE浏览器的AJAX调用的作品

但不是在Firefox和IE浏览器的AJAX调用的作品

本文介绍了在Chrome和Safari,但不是在Firefox和IE浏览器的AJAX调用的作品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code柜面用户忘记了密码重置用户密码。该数据是通过AJAX请求发送到PHP code和PHP code简单地呼应了Y或N根据输入的有效性。

现在的问题是,Ajax调用不会在Firefox 19和IE 9的工作我还没有在其他版本的IE浏览器尝试。 Ajax调用在Chrome和Safari正常工作。有没有人经历过同样的问题?任何人都可以帮助吗?

   

 <冠军>忘了密码? < /标题>

    &所述;脚本的src =的http://$c$c.jquery.com/jquery-latest.js>&所述; /脚本>
    <脚本类型=文/ JavaScript的SRC =htt​​p://jzaefferer.github.com/jquery-验证/ jquery.validate.js>< / SCRIPT>

    <风格类型=文本/ CSS>

        label.error {颜色:红色; }

        #status {颜色:绿色; }

    < /风格>

    <脚本>

        $(文件)。就绪(函数(){

            $('#code_form')隐藏()。

            $('#password_form)隐藏()。

            $(#email_form)。验证({

                的onkeyup:假的,

                规则:{

                  电子邮件: {
                    要求:真实,
                    电子邮件:真实的
                  }
                },

                消息:{
                  电子邮件: {
                  要求:请输入您的电子邮件ID。
                  电子邮件:请输入一个有效的电子邮件ID。
                 }
               }

            });


            $('#email_send)。点击(函数(){

                。事件preventDefault();

                变种的电子邮件= $('#邮件)VAL()。

                $阿贾克斯({
                    键入:POST,
                    网址:reset_ code.php

                    数据:{电子邮件:电子邮件},
                    缓存:假的,
                    成功:函数(响应){

                    如果(响应==Y)
                    {
                        $('#code_form')显示()。
                        $('#email_send)隐藏()。
                        $('#状态)HTML(查看邮件复位code);

                    }
                    其他
                    {

                        $('#状态)HTML(看来你输入了错误的电子邮件ID。);

                    }

                 }

            });

            });


            $(#code_form)。验证({

                的onkeyup:假的,

                规则:{

                  code:{
                    要求:真实,
                    数字:真
                  }
                },

                消息:{
                  code:{
                  要求:请输入你的邮箱里收到了code。
                  数字:请输入code在收到您的邮件。
                 }
               }

             });

             $('#code_send)。点击(函数(){

               。事件preventDefault();

               变种的电子邮件= $('#邮件)VAL()。
               变量code = $('#code')VAL()。


                $阿贾克斯({
                键入:POST,
                网址:code_verify.php

                数据:{电子邮件:电子邮件,code:code},
                缓存:假的,
                成功:函数(响应){

                    如果(响应==Y)
                    {
                        $('#password_form)显示()。
                        $('#code_send')隐藏()。
                        $('#状态)HTML(好了,现在输入密码两次,然后又忘了。)。

                    }
                    其他
                    {
                        $('#状态)HTML(请输入code在收到您的邮件。)。
                    }

                }

            });

            });


            $(#password_form)。验证({

                的onkeyup:假的,

                规则:{

                  密码: {
                    要求:真实,
                    MINLENGTH:8
                  },
                  确认密码:{
                    要求:真实,
                    equalTo:#Password来
                  }
                }

            });

            $('#password_send)。点击(函数(){

               。事件preventDefault();

               变种的电子邮件= $('#邮件)VAL()。
               VAR密码= $('#密码)VAL()。
               。VAR确认密码= $('#确认密码)VAL();

                $阿贾克斯({
                    键入:POST,
                    网址:update_password.php

                    数据:{电子邮件:电子邮件,密码:密码,确认密码:确认密码},
                    缓存:假的,
                    成功:函数(响应){

                    如果(响应==Y)
                    {

                        $('#email_form)隐藏()。
                        $('#code_form')隐藏()。
                        $('#password_form)隐藏()。
                        $('#状态)HTML(密码重置成功继续到< A HREF =的index.php>登录< / A>页);


                    }
                    其他
                    {
                        $('#状态)HTML(哎呀出事了再试一次。)。

                    }

                }


            });

        });

    });


    < / SCRIPT>

< /头>

<体类=oneColElsCtr>

    < D​​IV CLASS =about_body>

        < A HREF =的index.php>< IMG SRC =图像/ title_block_logon.png的风格=margin-顶:25像素;保证金底:-10px;/>< / A>&LT ; BR />

        < D​​IV ID =身份级=警戒警报,成功的风格=的margin-top:20px的;宽度:400像素;保证金左:235px;保证金底:30像素;>

            < H4类=警告,标题为>重置您的密码< / H4>

        < / DIV>

        <窗​​体类=形横NAME =email_formID =email_form方法=POST行动=>

            <字段集>

                < D​​IV CLASS =控制组的风格=保证金左:230px>

                    <标签类=控制标签>电子邮件< /标签>

                    < D​​IV CLASS =控制align =left>

                        <输入名称=电子邮件ID =电子邮件级=输入大型=文本占位符=输入你的邮箱ID/>

                    < / DIV>

                < / DIV>

                < D​​IV CLASS =控制组>

                    <按钮类型=提交ID =email_send级=BTN BTN-逆提交> GO< /按钮>

                < / DIV>

            < /字段集>

        < /形式GT;

        <窗​​体类=形横NAME =code_formID =code_form的方法=POST行动=>

            < P>输入code收到你的电子邮件和LT; / P>

            <字段集>

                < D​​IV CLASS =控制组的风格=保证金左:230px>

                    <标签类=控制标签> code< /标签>

                    < D​​IV CLASS =控制align =left>

                        <输入名称=codeID =code级=输入大型=文本占位符=#####/>

                    < / DIV>

                < / DIV>

                < D​​IV CLASS =控制组>

                    <按钮类型=提交ID =code_send级=BTN BTN-逆提交> GO< /按钮>

                < / DIV>

            < /字段集>

        < /形式GT;

        <表格样式=文本对齐:左>

            &其中; TR>

                < TD宽度=60%>

                    <窗​​体类=形横NAME =password_formID =password_form方法=POST行动=>

                        <字段集>

                            < D​​IV CLASS =控制组的风格=保证金左:90px;>

                                <标签类=控制标签>密码< /标签>

                                < D​​IV CLASS =控制>

                                    <输入名称=密码ID =密码级=输入大型=密码占位符=请输入您的密码的onfocus =Info_Over('#password_on_focus_info')的onblur =Info_Out('# password_on_focus_info')/>

                                < / DIV>

                            < / DIV>

                            < D​​IV CLASS =控制组的风格=保证金左:90px;>

                                <标签类=控制标签>确认密码< /标签>

                                < D​​IV CLASS =控制>

                                    <输入名称=确认密码ID =确认密码级=输入大型=密码占位符=重新输入密码/>

                                < / DIV>

                            < / DIV>

                            < D​​IV CLASS =控制组的风格=保证金左:250像素;>

                                <按钮类型=提交ID =password_send级=BTN BTN-逆提交> CONFIRM< /按钮>

                            < / DIV>

                        < /字段集>

                    < /形式GT;

                < / TD>

                < TD WIDTH =400像素VALIGN =顶的风格=填充右:130px>

                    <跨度ID =password_on_focus_info的风格=显示:无;>

                        密码应为8个字符以上。选择一个强口令是大写和小写字母的情况下,符号和数字的组合。

                     < / SPAN>

                < / TD>

            < / TR>

        < /表>

    < / DIV>

< /身体GT;
< / HTML>
 

解决方案

您必须使用一个事件对象的事件处理,镀铬的参数和Safari有一个名为事件的事件触发,但Firefox没有,当一个全局事件对象不。因此,事件preventDefault(); 将导致错误

例如。

  $('#email_send)。点击(函数(事件){
 

This is my code to reset a user's password incase the user forgets his password. The data is sent to the PHP code via AJAX requests and the PHP code simply echoes a "Y" or "N" depending upon the validity of the inputs.

The problem is, the AJAX calls does not work in Firefox 19 and IE 9. I haven't tried in other versions of IE. The AJAX calls work perfectly in chrome and safari. Has anyone been through the same problem? Can anyone help please?

    <title> Forgot Password? </title>

    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="http://jzaefferer.github.com/jquery-  validation/jquery.validate.js"></script>

    <style type="text/css">

        label.error { color: red;  }

        #status { color: green; }

    </style>

    <script>

        $(document).ready(function(){

            $('#code_form').hide();

            $('#password_form').hide();

            $("#email_form").validate({

                onkeyup: false,

                rules: {

                  email: {
                    required: true,
                    email: true
                  }
                },

                messages: {
                  email: {
                  required: "Please enter your email ID.",
                  email: "Please enter a valid email ID."
                 }
               }

            });


            $('#email_send').click(function() {

                event.preventDefault();

                var email = $('#email').val();

                $.ajax({
                    type: "POST",
                    url: "reset_code.php",

                    data: {email: email},
                    cache: false,
                    success: function(response){

                    if(response == "Y")
                    {
                        $('#code_form').show();
                        $('#email_send').hide();
                        $('#status').html("Check your mail for the reset code.");

                    }
                    else
                    {

                        $('#status').html("Looks like you have entered a wrong email ID.");

                    }

                 }

            });

            });


            $("#code_form").validate({

                onkeyup: false,

                rules: {

                  code: {
                    required: true,
                    digits: true
                  }
                },

                messages: {
                  code: {
                  required: "Please enter the code received in your mail.",
                  digits: "Please enter the code received in your mail."
                 }
               }

             });

             $('#code_send').click(function() {

               event.preventDefault();

               var email = $('#email').val();
               var code = $('#code').val();


                $.ajax({
                type: "POST",
                url: "code_verify.php",

                data: {email: email, code: code},
                cache: false,
                success: function(response){

                    if(response == "Y")
                    {
                        $('#password_form').show();
                        $('#code_send').hide();
                        $('#status').html("Ok, now enter your password twice before you forget again.");

                    }
                    else
                    {
                        $('#status').html("Please enter the code received in your mail.");
                    }

                }

            });

            });


            $("#password_form").validate({

                onkeyup: false,

                rules: {

                  password: {
                    required: true,
                    minlength: 8
                  },
                  repassword: {
                    required: true,
                    equalTo: "#password"
                  }
                }

            });

            $('#password_send').click(function() {

               event.preventDefault();

               var email = $('#email').val();
               var password = $('#password').val();
               var repassword = $('#repassword').val();

                $.ajax({
                    type: "POST",
                    url: "update_password.php",

                    data: {email: email, password: password, repassword: repassword},
                    cache: false,
                    success: function(response){

                    if(response == "Y")
                    {

                        $('#email_form').hide();
                        $('#code_form').hide();
                        $('#password_form').hide();
                        $('#status').html("Password reset successful. Proceed to <a href=index.php>login</a> page. ");


                    }
                    else
                    {
                        $('#status').html("Oops. Something went wrong. Try again.");

                    }

                }


            });

        });

    });


    </script>

</head>

<body class="oneColElsCtr">

    <div class ="about_body">

        <a href="index.php"><img src="images/title_block_logon.png" style="margin-    top:25px; margin-bottom:-10px;"/></a><br/>

        <div id="status" class="alert alert-success"  style="margin-top:20px; width:400px; margin-left:235px; margin-bottom:30px;">

            <h4 class="alert-heading"> Reset your password </h4>

        </div>

        <form class="form-horizontal" name="email_form" id="email_form" method="POST" action="" >

            <fieldset>

                <div class="control-group" style="margin-left:230px">

                    <label class="control-label">Email</label>

                    <div class="controls" align="left">

                        <input name="email" id="email" class="input-large" type="text" placeholder="Enter your Email id"/>

                    </div>

                </div>

                <div class="control-group">

                    <button type="submit" id="email_send" class="btn btn-inverse submit">GO</button>

                </div>

            </fieldset>

        </form>

        <form class="form-horizontal" name="code_form" id="code_form" method="POST" action="" >

            <p>Enter the code received in your Email</p>

            <fieldset>

                <div class="control-group" style="margin-left:230px">

                    <label class="control-label">Code</label>

                    <div class="controls" align="left">

                        <input name="code" id="code" class="input-large" type="text" placeholder="#####"/>

                    </div>

                </div>

                <div class="control-group">

                    <button type="submit" id="code_send" class="btn btn-inverse  submit">GO</button>

                </div>

            </fieldset>

        </form>

        <table style="text-align:left">

            <tr>

                <td width="60%">

                    <form class="form-horizontal" name ="password_form" id="password_form" method ="POST" action ="" >

                        <fieldset>

                            <div class="control-group" style="margin-left:90px;">

                                <label class="control-label">Password</label>

                                <div class="controls">

                                    <input name="password" id="password" class="input-large" type="password" placeholder="Enter your Password" onfocus="Info_Over('#password_on_focus_info')" onblur="Info_Out('#password_on_focus_info')"/>

                                </div>

                            </div>

                            <div class="control-group" style="margin-left:90px;">

                                <label class="control-label">Confirm Password</label>

                                <div class="controls">

                                    <input name="repassword" id="repassword" class="input-large" type="password" placeholder="Re-enter your Password"/>

                                </div>

                            </div>

                            <div class="control-group" style="margin-left:250px;">

                                <button type="submit" id="password_send" class="btn btn-inverse submit">CONFIRM</button>

                            </div>

                        </fieldset>

                    </form>

                </td>

                <td width="400px" valign="top" style="padding-right:130px">

                    <span id="password_on_focus_info" style="display:none;">

                        Password should be 8 characters or more. Choose a strong password which is a combination of Capital and Small case alphabets, Symbols and Numbers.

                     </span>

                </td>

            </tr>

        </table>

    </div>

</body>
</html>
解决方案

You have to use an event object for the parameter of the event handler, chrome and safari has a global event object called event when an event is triggered but firefox does not. So event.preventDefault(); will cause an error.

E.g.

$('#email_send').click(function(event) {

这篇关于在Chrome和Safari,但不是在Firefox和IE浏览器的AJAX调用的作品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 18:56