Blogger Information
Blog 32
fans 0
comment 0
visits 23513
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
$.get .post .ajax区别-2019年5月22日20点00分
小李广花荣
Original
659 people have browsed it
  1. 下面将展示ajax中常用的几种


  2. 实例

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>$.post()</title>
        <script src="static/js/jquery-3.4.1.js"></script>
    </head>
    <body>
    <h3>用户登录$.post()</h3>
    <p><label for="email">邮箱:</label><input type="email" id="email" name="email"></p>
    <p><label for="password">密码:</label><input type="password" id="password" name="password"></p>
    <p><button id="submit">提交</button></p>
    
    <script>
    
        var email=$('#email');
        var password=$('#password');
        var btn=$('#submit');
    
        btn.on('click',isEmpty);
        function isEmpty(){
    
            if (email.val().length === 0) {
                email.after('<span style="color:red">邮箱不能为空</span>').next().fadeOut(2000);
                email.focus();
                return false;
            } else if (password.val().length === 0) {
                password.after('<span style="color:red">密码不能为空</span>').next().fadeOut(2000);
                password.focus();
                return false;
            } else if (password.val().length < 6) {
                password.after('<span style="color:red">密码不能少于6位</span>').next().fadeOut(2000);
                password.focus();
                return false;
            } else {
                checkUser1()
            }
        }
        function checkUser() {
    
            $.post(
                'inc/check.php',
                {
                    email:email.val(),
                    password:password.val()
                },
                function (data) {
    
                    if (data.status===1){
                        $('button')
                            .after('<span style="color: green"></span>')
                            .next()
                            .html(data.message)
                            .fadeOut(2000);
                    }else {
                        $('button')
                            .after('<span style="color: red"></span>')
                            .next()
                            .html(data.message)
                            .fadeOut(2000);
                    }
                },
                'json'
    
            )
    
        }
        function checkUser1() {
            $.ajax(
                {
                    type:'POST',
                    url:'inc/check.php',
                    data:{
                        email: email.val(),
                        password: password.val()
                    },
                    success:function (data) {
    
                        if(data.status===1){
                            $('button')
                                .after('<span style="color: green"></span>')
                                .next()
                                .html(data.message)
                                .fadeOut(2000);
                        }else {
                            $('button')
                                .after('<span style="color: red"></span>')
                                .next()
                                .html(data.message)
                                .fadeOut(2000);
                        }
    
                    },
                    dataType:'json'
                }
            )
        }
    
    
    </script>
    </body>
    </html>

    运行实例 »

    点击 "运行实例" 按钮查看在线实例

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!