AJAX不适用于默认域工作 [英] ajax doesn't work for default domain
问题描述
我有一个AJAX脚本,在主index.php页面,从一个绝对的URL获取数据:'http://www.example.com/ajax
I have an ajax script, in the main index.php page, that fetches data from an absolute URL: 'http://www.example.com/ajax'
现在的问题是,该取的作品,当我从运行 http://www.example.com ,但我只是去 http://example.com ,虽然页面加载蛮好的休息,AJAX脚本赢得T承载。
The problem is that the fetch works when I run it from http://www.example.com, but I just go to http://example.com, though the rest of the page loads just fine, the ajax script won't load.
有谁知道任何可能的原因,这可能是这种情况?
Does anyone know of any possible reason why this may be the case?
推荐答案
在同源策略运行在主机名的基础上,而不是域的基础。
The same origin policy operates on a hostname basis, not a domain basis.
使用相对URI,或者选择一个主机名,作为典型的和重定向所有流量从一个到另一个。
Use relative URIs, or pick one hostname as canonical and redirect all traffic from one to the other.
这篇关于AJAX不适用于默认域工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!