1***@qq.com
1***@qq.com
  • 发布:2018-10-05 14:55
  • 更新:2018-10-05 14:55
  • 阅读:1662

mui注册[object HTMLInputElement]问题求解答(附详细代码)

分类:MUI

前端:

<!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>  
        <script src="js/mui.min.js"></script>  
        <link href="css/mui.min.css" rel="stylesheet"/>  
        <script type="text/javascript" charset="utf-8">  
            mui.init();  
        </script>  
    </head>  
    <body>  
        <div class="mui-content">  
            <header class="mui-bar mui-bar-nav">  
                <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>  
                <h1 class="mui-title">注册</h1>  
            </header>  
            <form class="mui-input-group" style="margin-top:45px ;">  
                <div class="mui-input-row">  
                    <label>用户名</label>  
                <input type="text" class="mui-input-clear" placeholder="请输入用户名" id="username">  
                </div>  
                <div class="mui-input-row">  
                    <label>密码</label>  
                    <input type="password" class="mui-input-password" placeholder="请输入密码" id="password">  
                </div>  
                <div class="mui-input-row">  
                <label>email</label>  
                <input type="text" class="mui-input-clear" placeholder="请输入邮箱" id="email">  
            </div>  
                <div class="mui-button-row">  
                    <button type="button" class="mui-btn mui-btn-primary" id="yes">确认</button>  
                    <button type="button" class="mui-btn mui-btn-danger" >取消</button>  
                </div>  
            </form>  
        </div>  
    </body>  
    <script type="text/javascript">  
        function caseajax(){  
            console.log(username,password)  
            mui.ajax('http://172.28.29.24:8081/php/reg.php',{  
                data:{  
                    username:'username.value',  
                    password:'password.value',  
                    email:'email.value'  
                },  
                dataType:'json',//服务器返回json格式数据  
                type:'post',//HTTP请求类型  
                timeout:10000,//超时时间设置为10秒;  
                headers:{'Content-Type':'application/json'},                    
                success:function(data){  
                    console.log(data)  
                },  
                error:function(xhr,type,errorThrown){  
                    //异常处理;  
                    console.log(type);  
                }  
            })  
        }  
        document.getElementById("yes").addEventListener("tap",function(){caseajax()})  
    </script>  
</html>  

```javascript
```后端:  
<?php  
    header("Content-type:text/html;charset=utf-8");  
    header("Access-Control-Allow-Origin: *");   //跨域  
if(!isset($_POST['submit'])){exit("非法访问!");}  
$username = $_POST['username'];  
$password = $_POST['password'];  
$email = $_POST['email'];  
//注册信息判断  
if(!preg_match('/^[\w\x80-\xff]{3,30}$/', $username)){  
    exit('错误:用户名不符合规定。<a href="javascript:history.back(-1);">返回</a>');  
}  
if(strlen($password) < 6){  
    exit('错误:密码长度不符合规定。<a href="javascript:history.back(-1);">返回</a>');  
}  
if(!preg_match('/^\w+@\w+(\.[a-zA-Z]{2,3}){1,2}$/', $email)){  
    exit('错误:电子邮箱格式错误。<a href="javascript:history.back(-1);">返回</a>');  
}  
//包含数据库连接文件  
include('conn.php');  
//检测用户名是否已经存在  
//$check_query = mysqli_query($conn,"select uid from user where username='$username' limit 1");  
//if(mysqli_fetch_array($check_query)){  
//echo '错误:用户名 ',$username,' 已存在。<a href="javascript:history.back(-1);">返回</a>';  
//exit;  
//}  

//if (!$check_query) {  
//printf("Error: %s\n", mysqli_error($dbc));  
//exit();  
//}  
//写入数据  
$password = MD5($password);  
$regdate = time();  
$sql = "INSERT INTO user(username,password,email,regdate)VALUES('$username','$password','$email',  
$regdate)";  
if(mysqli_query($GLOBALS['conn'],$sql)){  
    exit('用户注册成功!点击此处 <a href="../login.html">登录</a>');  
} else {  
    echo '抱歉!添加数据失败:',mysqli_error($conn),'<br />';  
    echo '点击此处 <a href="javascript:history.back(-1);">返回</a> 重试';  
}  
?>  


没有ajax进程啊,求解答

2018-10-05 14:55 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复