Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

如何获取网络时间

$
0
0

@unrealistic 写道:

被这个问题困扰很久了,最下面是网上找到的一段代码,在IE中能正常获取时间,
不是IE环境应该是用XMLHttpRequest吧,这时候就出现
HelloWorld.js:30XMLHttpRequest cannot load http://bjtime.cn/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:7456' is therefore not allowed access.
大概是跨域的问题吧,然后在网上搜索关于跨域的问题,大概也看到一些答案不知道如何实施,能做的好像就
response.setHeader("Access-Control-Allow-Origin", "*");或者addHeader都没用,不知道是写在哪,还是creator是其他的写法。实在解决不了了,希望能得到帮助,先谢谢了

var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
xmlhttp.open("GET", "http://bjtime.cn", false);
xmlhttp.setRequestHeader("If-Modified-Since", "bjtime");
xmlhttp.send();
var dateStr = xmlhttp.getResponseHeader("Date");
var date = new Date(dateStr);

帖子: 1

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>