JS 利用 XMLHttpRequest 跨域获取数据。

var req = new XMLHttpRequest();if (req != null) {    req.onreadystatechange = function() {        //// Checks the asyn request completed or not.        if (req.readyState == 4) {            if ((req.status >= 200 && req.status < 300) || req.status == 304) {                alet(req.responseText);    //获取成功就弹出取得的内容            } else {                alert("Request was unsuccessful: " + req.status);            }        }    };    req.open("GET",URL, true);    //url是获取的地址    req.send(null);};

 

 
 

你可能感兴趣的:(XMLhttpREquest)