jQuery用户从服务器端注册登录
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>用户登录</title> 6 <script src="jquery-3.1.0.js"></script> 7 </head> 8 <body> 9 <form> 10 <label>账户</label><input type="text" class="name loginName" name="username"> 11 <label>密码</label><input type="password" class="password loginPassword" name="password"> 12 <input type="button" value="提交" id="submit"> 13 <a value="登录" id="login">登录</a> 14 </form> 15 <script> 16 $("#submit").click(function (e) { 17 e.preventDefault(); 18 $.ajax({ 19 url: "http://datainfo.duapp.com/shopdata/userinfo.php", 20 method: "POST", 21 dataType: "json", 22 data: { 23 status: "register", 24 userID: $(".name").val(), 25 password: $(".password").val() 26 }, 27 success: function (data) { 28 console.log(data) 29 }, 30 error: function () { 31 console.log("error") 32 } 33 }) 34 }); 35 $("#login").click(function (e) { 36 e.preventDefault(); 37 $.ajax({ 38 url: "http://datainfo.duapp.com/shopdata/userinfo.php", 39 method: "POST", 40 dataType: "json", 41 data: { 42 status: "login", 43 userID: $(".loginName").val(), 44 password: $(".loginPassword").val() 45 }, 46 success: function (data) { 47 console.log(data); 48 }, 49 error: function () { 50 console.log("error"); 51 } 52 }); 53 }) 54 </script> 55 </body> 56 57 </html>
myGitgub https://github.com/mfx55
希望我的博客能帮到你