梦见Utaoki 2023-02-13 17:00 采纳率: 85.2%
浏览 41
已结题

基于node.js的注册登录界面,电脑端正常,手机端点击没反应

手机端点击注册按钮无反应估计是前端的问题,请教,网站:http://tou365.cn/initnode/sign_in.html
用的是BootStrap5,代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册新用户</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js"></script>
    
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css">

<script src="https://cdn.staticfile.org/popper.js/2.9.3/umd/popper.min.js"></script>
 

<script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.min.js"></script>
<script>       function oncheck(form){
    if(form.uname.value =='' && form.pwd.value =='' || form.uname.value =='' && form.pwd.value !='' ) 
    {alert('用户名不能为空哈!')  
}; if(form.uname.value !='' && form.pwd.value =='') {alert('密码不能为空哈')
    };if(form.uname.value =='' && form.pwd.value ==''){ alert('用户名与密码不能为空哈')}
}</script>
</head>
<body>
    <div style="width:130px;margin:0 auto;font-size:xx-large;margin-top: 20px;">开源社区</div>
    <div class="container" style="width: 250px;margin-top: 20vh;border:1px solid rgba(128, 128, 128, 0.831);border-radius: 20px;padding:30px;" > 
        <h5>用户注册</h5>
        <form action="" class="" onsubmit="oncheck(this);return false;const num=1">
    <input type="text" name="uname" id="user" class="form-control" placeholder="用户名">
    <br>
    <input type="text" name="pwd" id="pwd" class="form-control" placeholder="密码">
    <button class="btn btn-primary" style="margin-top: 20px;" >注册</button>
</form>
</div>
<script>
    document.querySelector('.btn').onclick = function(){
        //e.stopPropagation()
         const name = document.querySelector('#user').value
    const pwd = document.querySelector('#pwd').value   
    const xhr = new XMLHttpRequest()
    xhr.open('post','http://127.0.0.1:3007/api/reguser')
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
    xhr.send(
        'username='+name+'&password='+pwd
    )
    xhr.onreadystatechange = function(){
        if(xhr.readyState ===4){
            if(xhr.status >=200 && xhr.status <300){
                getjson('message')
                function getjson(key){
                    var  val = xhr.responseText
                    //var va = {"name":"傅红雪","age":"24","profession":"刺客"}//
                   var finval = jQuery.parseJSON(val)
                   console.log(finval)
                    console.log(typeof(finval))
                    var eValue=eval('finval.'+key)
                    alert(eValue);
                    if(eValue =='注册成功!'){window.location.href = './login_in.html'}
                }
               
                //console.log(val)               
                // jsonObj=val.substring(1,val.length-1);
                //console.log()
           //alert(msg)
                
            }
        }
    };
    }
</script>
</body>
</html>

  • 写回答

3条回答 默认 最新

  • 简效 2023-02-13 17:09
    关注

    你的请求地址有问题,这样试一下

    http://127.0.0.1:3007/api/reguser改成 /api/reguser
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 2月22日
  • 已采纳回答 2月14日
  • 创建了问题 2月13日

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题