10 jQuery ajax request of

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jquery的ajax请求</title>
</head>
<body>
    <div class="box"></div>
    <form >
        <input type="text" name="user" placeholder="name">
        <input type="text" name="password" placeholder="password">
        <input type="submit" name="">
    </form>
    <script type="text/javascript" src="jquery-3.3.1.js"></script>
    <script type="text/javascript">
        $(function () {
            $.ajax({
                url:'http://localhost:8080',
                type:'get',
                success:function (data) {
                    $('.box').append(data);
                    console.log(data)
                },
                error:function (err) {
                    console.log(err)
                }
            });

            $.ajax({
                url:'http://localhost:8080/course',
                type:'get',
                dataType:'json', //String parameter type requirements, type of data expected server returns 
                Success: function (Data) { 
                    $ ( ' .box ' ) .text (data.name); 
                    the console.log (Data) 
                }, 
                error: function (ERR) { 
                    the console.log (ERR) 
                } 
            }); 
            $ ( ' form ' ) .submit ( function (E) { 
                e.preventDefault (); 
                var name_val = $ ( ' INPUT [User name =] ' ) .val ();
                var pwd = $('input[name=password]').val();
                $.ajax({
                    url:'http://localhost:8080/create/user',
                    type:'post',
                    data:{
                        name:name_val,
                        password:pwd
                    },
                    success:function (data) {
                        console.log(data);
                    },
                    error:function (err) {
                        console.log(err);
                    }
                })
            })

        })
    </script>
</body>
</html>

 

Guess you like

Origin www.cnblogs.com/znyyy/p/11119687.html