你能让我明白为什么这段代码似乎无法正常工作吗?基于国家的简单jquery重定向工作不正常
<html><head><title></title>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
jQuery.ajax({
url: '//freegeoip.net/json/',
type: 'POST',
dataType: 'jsonp',
success: function(location) {
// If the visitor is browsing from Romania or GB
if (location.country_code === 'RO' || 'GB') {
// Redirect him to the Canadian store.
window.top.location.href = 'http://shop-in-canada.myshopify.com';
}
else
{ return false; }
}
});
</script>
</head><body></body></html>
通过适当我的意思是,这重定向我的shop-in-canada.myshopify.com连我都GB或RO或美国或CA或任何其他国家。你认为这个问题来自哪里?
你能尝试用下面这样的'''dataType''','''数据:JSON.stringify''' – FreedomPride
本文归“的XMLHttpRequest无法加载http://freegeoip.net/json/。所请求的资源上没有'Access-Control-Allow-Origin'标头,因此Origin'site .com'不允许访问,响应的HTTP状态码为405。在控制台中。但感谢您的帮助。 @saravanan答案帮助我所有我需要的! – Adrian