ajax同步请求JS代码

时间:2023-03-09 21:21:34
ajax同步请求JS代码

ajax同步请求JS代码

	<script type="text/javascript">
var txt = document.getElementById('txt');
//1.创建XMLHttpRequest对象
var xhr = null;
if(window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}else {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
//2.打开与服务器的链接
xhr.open('get',url,false);
//3.发送给服务器
xhr.send(null);
//4.响应就绪(同步请求)
var json = JSON.parse(xhr.responseText);
txt.innerHTML = json;
console.log('其他程序');
</script>

  

相关文章