一个mui+ajax+php的demo
生活随笔
收集整理的這篇文章主要介紹了
一个mui+ajax+php的demo
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
html源碼
<!DOCTYPE html> <html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /><title></title><link href="css/mui.min.css" rel="stylesheet" /></head><body><div class="mui-content"><form class="mui-input-group"><div class="mui-input-row"><label>用戶名</label><input type="text" id="username" placeholder="用戶名"></div><div class="mui-input-row"><label>密碼</label><input type="password" id="password" placeholder="密碼"></div></form><div style="margin-top:20px;text-align: center;"><button class="mui-btn mui-btn-primary" id="loginBtn">登錄</button></div></div><script src="js/mui.min.js"></script><script type="text/javascript" charset="utf-8">(function($, doc) {$.init({statusBarBackground: '#f7f7f7'});$.plusReady(function() {document.getElementById("loginBtn").addEventListener("tap", function() {var username = document.getElementById("username").value;var password = document.getElementById("password").value;mui.ajax('http://localhost/ServerJson.php', {data: {username: username,password: password},dataType: 'json', //服務(wù)器返回json格式數(shù)據(jù)type: 'post', //HTTP請(qǐng)求類型timeout: 10000, //超時(shí)時(shí)間設(shè)置為10秒;success: function(data) {var result = eval('(' + data + ')'); //js原生方法解析json字符串為json對(duì)象if(result != 1) {// 如果密碼錯(cuò)誤,提示一下信息 mui.alert("用戶名或密碼錯(cuò)誤", "登錄錯(cuò)誤", "關(guān)閉");//mui.alert(result);return;}mui.openWindow({url: 'main.html',id: 'main',});},error: function(xhr, type, errorThrown) {}});});});}(mui, document));</script></body> </html>php代碼
<?php header('Content-type:text/html; Charset=utf8'); header( "Access-Control-Allow-Origin:*"); header('Access-Control-Allow-Methods:POST'); header('Access-Control-Allow-Headers:x-requested-with,content-type'); $name=$_POST['username']; $pwd=$_POST['password']; $con = mysqli_connect('localhost','user','password','dbname');//鏈接數(shù)據(jù)庫 //mysql_set_charset($link,'utf8'); //設(shè)定字符集if(!$con){ die('error:'.mysql_error()); } $sql_select="select username,password from pre_common_member where username= ?"; //從數(shù)據(jù)庫查詢信息 $stmt=mysqli_prepare($con,$sql_select);mysqli_stmt_bind_param($stmt,'s',$name);mysqli_stmt_execute($stmt);$result=mysqli_stmt_get_result($stmt);$row=mysqli_fetch_assoc($result);if($row){ if($row['password']==$pwd){ echo 1;//普通用戶 }else{ echo 3;//密碼錯(cuò)誤 } }else{ echo 4;//用戶不存在 } ?>
轉(zhuǎn)載于:https://www.cnblogs.com/xiede/p/8999312.html
總結(jié)
以上是生活随笔為你收集整理的一个mui+ajax+php的demo的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

- 上一篇: Linux(DeepInOS) 下 my
- 下一篇: async/await 的基本实现和 .