前端项目实战陆-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 @   前端导师歌谣  阅读(9)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示