<!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>Document</title>
</head>
<body>
<button id="get">GET</button>
<br>
<button id="post">POST</button>
<br>
<div id="div"></div>
</body>
</html>
<script>
window.onload = function(){
const get = document.querySelector('#get')
const post = document.querySelector('#post')
const div = document.querySelector('#div')
get.onclick = function(){
console.log('点击了get按钮') //当点击按钮之后这里执行了
let xhr = new XMLHttpRequest()
xhr.onreadystatechange = function(){
console.log('asd') //当点击按钮之后这里没有执行
if(this.readyState == 4 && this.status ==200){
div.innerHTML = this.responseText
}
xhr.open('GET','http://127.0.0.1/api/get?a=1',true) //跨域了,应该会有一个报错吧,但是没反应
xhr.send()
}
}
}
</script>
ajax请求没有反应
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
相关推荐 更多相似问题
点击登录
提问题
悬赏问题
- ¥15 python对txt文件的处理
- ¥25 需要一个能在H5中实现扫码的插件
- ¥50 ArcGIS或MATLAB实现批量计算整个tif图像的EVI
- ¥20 两个板子之间CAN通信ID号怎么设置
- ¥15 两个板子CAN通信的话ID号怎么设置
- ¥15 vue使用element-ui的el-upload上传图片至服务器,服务端使用的是node.js,图片上传成功,但界面显示不出来,是跨域问题?
- ¥15 ANSYS APDL循环结果输出
- ¥15 ArcGIS处理MODIS 09数据,计算EVI 像元值大小问题
- ¥15 Python库一直装不好
- ¥30 在linux上调用海康SDK没有进入函数内