前端项目实战陆-pad端原生网络请求页面无反应

大家好 我是歌谣 记录工作中遇到的各种问题 微信公众号关注前端小歌谣持续学习前端知识 

样式.html 

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title></title>
	 <link rel="stylesheet" type="text/css" href="./login/css/index.css">

</head>
<body>
	<h2>拉波尼质检系统管理</h2><br>
	<div class="login">
	    <form id="login" method="get">
	        <label><b>账 号:</b></label>
	        <input type="text" name="Uname" id="Uname" maxlength="100" placeholder="请输入账号">
	        <br><br>
	        <label><b>密 码:</b></label>
	        <input type="Password" name="Pass" id="Pass" placeholder="请输入密码">
	        <br><br>
	       <input type="button" name="log" id="log" value="登录">
	        <br><br>
	    </form>
	</div>
	<div id="logList">11111</div>
	 <script type="text/javascript" src="login/js/login.js">
</body>
</html>

 原生.js

		var Uname=document.getElementById("login")
		 var Pass=document.getElementById("Pass")
		 var log=document.getElementById("log")
		 var logList=document.getElementById("logList")
		 //绑定点击事件
		 log.addEventListener("click",function(){
			 console.log(2222)
		
				var http = {};
				http.quest = function (option, callback) {
				  var url = option.url;
				  var method = option.method;
				  var data = option.data;
				  var timeout = option.timeout || 0;
				  var xhr = new XMLHttpRequest();
				  
				  (timeout > 0) && (xhr.timeout = timeout);
				  xhr.onreadystatechange = function () {
				    if (xhr.readyState == 4) {
				      if (xhr.status >= 200 && xhr.status < 400) {
				        var result = xhr.responseText;
				        try { result = JSON.parse(xhr.responseText); } catch (e) { }
				        callback && callback(null, result);
				      } else {
				        callback && callback('status: ' + xhr.status);
				      }
				    }
				  }.bind(this);
				  xhr.open(method, url, true);
				  xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8');
				  if (typeof data === 'object') {
				    try {
				      data = JSON.stringify(data);
				    } catch (e) { }
				  }
				  xhr.send(data);
				  xhr.ontimeout = function () {
				    callback && callback('timeout');
	
				  };
				};
				http.get = function (url, callback) {
				  var option = url.url ? url : { url: url };
				  option.method = 'get';
				  this.quest(option, callback);
				};
				http.post = function (option, callback) {
				  option.method = 'post';
				  this.quest(option, callback);
				};
				http.post({ url: 'http://218.4.25.5:10006/pda/login', data: {
					account:document.getElementById("Uname").value,
					password:document.getElementById("Pass").value
				}, timeout: 1000 }, function (err, response) {
					console.log(response,"response")
				    if(response.code==200){
						window.location.href="./home.html"
					}
				});
});

 运行结果

测试后没有反应 

posted @ 2023-06-29 09:35  前端导师歌谣  阅读(20)  评论(0)    收藏  举报  来源