目前的需求很簡單, 就是拿到這個網站提供的當前時間網站上提供了JSONP示例但我能用原生ajax來獲取這個json數(shù)據嗎?期間遇到的跨域問題又怎么解決呢?求解!比如var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function(){ console.log('changed!');
if(this.readyState === XMLHttpRequest.DONE){ if(this.status === 200){ console.log(this.responseText);
}
}
}
httpRequest.open('GET', 'http://www.timeapi.org/utc/now', true);
httpRequest.send(null);這段代碼在snippet里運行得很好但是搬到實際網站上就有跨域的問題了
原生ajax如何解決跨域問題?
慕虎7371278
2018-09-05 14:13:23