登陆
<body>
<button>登陆</button>
<h1></h1>
<script src="./jquery-1.12.4.js"></script>
<script>
$('button').click(function () {
/* $.ajax({
url: './login.txt',//接口,本地接口用get
type: 'get',//get方式
async: true,//异步
dataType: 'json',//数据转json类型
success: function (res) {
console.log(res);
$('h1').html(`姓名:
${res.name},${res.msg}`)
$('button').fadeOut('slow')
},
error: function () {
$('h1').html('请求失败')
}
});
*/
//get简版写法
/* $.get('./login.txt', function (data) {
let res = JSON.parse(data)
$('h1').html(`姓名:${res.name},${res.msg}`)
$('button').fadeOut('slow')
}) */
//post简版写法
let url = "http://timemeetyou.com:8889/api/private/v1/login";
$.post(url, { username: 'admin', password: '123456' }, function (res) {
//post第一个数表示接口地址,
//post第二个数表示传输数据,
//post第三个数表示成功回调函数,
console.log(res);
})
})
</script>
</body>