UNPKG

koa2-boilerplate-plus

Version:
67 lines (56 loc) 2.51 kB
<!doctype html><html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Cache-Control" content="no-cache"> <meta http-equiv="Expires" content="0"> <title>Index Page</title> <link href="//cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"> <script src="//cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script> </head> <body> </br> </br> <p><button class="btn btn-primary" data-toggle="button" id="btn1">测试LOGIN</button></p> </br> <p><button class="btn btn-primary" data-toggle="button" id="btn2">测试LOGOUT</button></p> <script> $(function() { $('#btn1').on('click', function(body) { $.ajax('/auth/login', { type: "POST", contentType: "application/json; charset=utf-8", data : JSON.stringify({"username":"test", "password":"test"}), async : true, success: function(data, status, xhr) { if(data.status == 400) { alert('Login errro') } else { alert('Login Success') } }, xhrFields: { withCredentials: true }, crossDomain: true }); }) $('#btn2').on('click', function(body) { $.ajax('/auth/logout', { type: "GET", contentType: "application/json", success: function(data, status, xhr) { alert('Logout success') }, xhrFields: { withCredentials: true }, crossDomain: true }) }) }) </script> </body> </html>