侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

AJAX 的使用

2024-05-11 星期六 / 0 评论 / 0 点赞 / 75 阅读 / 3627 字

<body> <div class="container"> <h2>ajax 操作实例</h2> <p>姓名:</p> <input type="text" id="name" /><br/

<body>
    <div class="container">
        <h2>ajax 操作实例</h2>
        <p>姓名:</p>
        <input type="text" id="name" /><br/>
        <p>年龄:</p>
        <input type="text" id="age" /><br/><br/>
        <input type="submit" id="sub" />
    </div>
        
    </body>
</html>
<script type="text/javascript">
alert(22);
        $('#sub').click(function(){
            var name = $('#name').val();
            var age  = $('#age').val();
            $.ajax({
                url:'__ACTION__',
                data:{
                    name:'name',
                    age :'age',
                },
                type:'get',
                // dataType:'json',
                success:function(msg){
                    if(msg==1){
                    alert(33);
                    clearInterval();
                    }
                },
                error:function(msg){
                    alert('error');
                }
            })
        })
        </script>

后台

public function ajax(){
        if(IS_AJAX){
         $this->ajaxReturn(1,'json');
        }
        
        $this->display();
    }

广告 广告

评论区