码迷,mamicode.com
首页 > Web开发 > 详细

xmlhttp js 请求

时间:2019-01-04 14:40:43      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:pen   proc   highlight   class   ==   new   请求   html   parse   

<html>
<script>
 
var xhr = new XMLHttpRequest();
xhr.open(‘GET‘, "http://ipinfo.io/json", true);
xhr.send();
 
xhr.onreadystatechange = processRequest;
 
function processRequest(e) {
 
	if (xhr.readyState == 4 && xhr.status == 200) {
        var response = JSON.parse(xhr.responseText);
           alert(response.ip);
    }
}

</script>
</html>

  

xmlhttp js 请求

标签:pen   proc   highlight   class   ==   new   请求   html   parse   

原文地址:https://www.cnblogs.com/xiaobaichuangtianxia/p/10148870.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!