美文网首页
JQuery AJAX用法

JQuery AJAX用法

作者: 叫我小码哥 | 来源:发表于2019-04-28 08:22 被阅读0次

html,css代码

<head>
    <meta charset="UTF-8">
    <title>主界面</title>
    <style type="text/css">
        body{
            background-image: url(img/2.png);
            background-repeat: no-repeat;
            background-size: 100% 120%;
        }
        .img td input{
            with: 80px;
            height: 30px;
        }
        font{
            color: #fafafa;
        }
    </style>
</head>
<body>
    <h1 align="center">主界面</h1>
    <form>
        <table class="table" align="center" width="300px"  border="0"  cellpadding="0"cellspacing="1">
            <tr>
                <td align="center" colspan="2"><img src="img/1.png" alt="假装有个图片" with="10%" height="10%"//></td>
            </tr>
            <tr>
                <td align="center" height="50px">用户名:</td>
                <td  height="50px"><input type="text" id="userPhone"/></td>
            </tr>
            <tr>
                <td align="center" height="50px">密码:</td>
                <td height="50px"><input type="password" id="userPassword"/></td>
            </tr>
            <tr>
                <td align="right" ><input type="radio" name="personId"  checked="checked" value="1"/>用户</td>         
                <td align="center"><input type="radio" name="personId" value="2"/>商家</td>
            </tr>

            <tr>
                <td height="80px" align="right" ><input type="button" id="login" value="登录"/></td>
                <td height="80px" align="center" ><input type="button" id="resign" value="注册"/></td>
            </tr>
        </table>
    </form>
</body>

Jquery AJAX

<script src="jquery.min (1).js"></script>
    <script type="text/javascript"> 
        //登录
        $("#login").click(function(){       
            if($('input:radio:checked').val() == 1){
                $.ajax({
                    url: 'http://127.0.0.1:8080/renting/user/login',
                    data: {
                        "userPhone": $("#userPhone").val(),
                        "userPassword": $("#userPassword").val(),
                    },
                    type: "get",
                    async: false,               
                    dataType: "jsonp",
                    jsonpCallback: "foo",
                    success: function (data) {                      
                        console.log(data);
                        if (data.statue === "SUCCEED" || data.bool === true){
                            alert("用户验证成功");
                            $(window).attr('location','show.html');
                        }else{
                            alert("用户名或密码有误");
                        }

                    },
                    error: function () {
                        alert('接收数据失败');
                    }
                });
            }else{
                $.ajax({
                    url: 'http://127.0.0.1:8080/renting/seller/login',
                    data: {
                        "sellerPhone": $("#userPhone").val(),
                        "sellerPassword": $("#userPassword").val(),
                    },
                    type: "get",
                    async: false,               
                    dataType: "jsonp",
                    jsonpCallback: "foo",
                    success: function (data) {
                        console.log(data);
                        if (data.statue === "SUCCEED" || data.bool === true){
                            alert("验证成功");
                            $(window).attr('location','businessResign.html');
                        }else{
                            alert("用户名或密码有误");
                        }
                    },
                    error: function () {
                        alert('接收数据失败');
                    }
                }); 
            
            }       
    
        });
    //注册
    $("#resign").click(function(){
        
        if($('input:radio:checked').val() == 1){
            $(window).attr('location','userResign.html');
        }else{
            $(window).attr('location','sellerResign.html');
        }
        
        
    
    });
    </script>

相关文章

  • jQuery ajax——参数详解

    详细学习jQuery ajax 用法 环境依赖jQuery (我用的是 jQuery v1.11.2) 通用写法$...

  • ajax

    定义和用法: ajax() 方法通过 HTTP 请求加载远程数据。 该方法是 jQuery 底层 AJAX 实现。...

  • JQuery AJAX用法

    html,css代码 Jquery AJAX

  • Jquery Ajax 封装

    Jquery Ajax封装 Jquery Ajax 调用

  • jQuery API学习之ajax与回调对象篇

    jQuery ajax 实例讲解 [$.get() 定义和用法]get()方法通过远程HTTP GET请求载入信息...

  • 2019-11-08

    简单理解jQuery中.get、.ajax用法 在WEB开发中异步请求方式普遍使用,ajax技术减少程序员的工作量...

  • Ajax实现登陆验证

    关于jquery与Ajax jQuery 提供多个与 AJAX 有关的方法。通过 jQuery AJAX 方法,能...

  • jQuery中的ajax

    一、jQuery中的ajax 封装第一层 - 类似于原生ajax的用法 $ajax 封装第二层 - 基于第一层再次...

  • jQuery中的Ajax

    jQuery中的ajax 封装第一层 - 类似于原生ajax的用法$ajax 封装第二层 - 基于第一层再次封装$...

  • ajax使用注意

    新版jQuery使用ajax: 旧版jQuery使用ajax:

网友评论

      本文标题:JQuery AJAX用法

      本文链接:https://www.haomeiwen.com/subject/rqyrnqtx.html