在实际尝试使用ajax方法之前,是否有"安全"的方法来检查相同的原始策略是否适用于URL?这是我有的:
function testSameOrigin(url) {
var loc = window.location,
a = document.createElement('a');
a.href = url;
return a.hostname == loc.hostname &&
a.port == loc.port &&
a.protocol == loc.protocol;
}
Run Code Online (Sandbox Code Playgroud)
这种作品,但它是一种基于维基百科文章的手动猜测.有没有更好的方法来预先检查跨域允许?jQuery可以使用.