写如下代码:
request = new XMLHttpRequest();
request.open('GET', url, true);
request.onreadystatechange = function() {
if (request.status >= 200 && request.status < 400){
// Success!
data = JSON.parse(request.responseText);
console.log(data);
if(data.ret == 1){
window.location = data.url;
}
}
};
request.send();
发现会提示:
XMLHttpRequest cannot load http://XXXXX.com/app.php?callback=cb. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.YYYY.com' is therefore not allowed access.
如何实现类似getJSON的JSONP跨域呢?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
人生最曼妙的风景,竟是内心的淡定与从容!