我想做一个适应当前方案(http/https
)的ajax调用。对于这种情况,什么是真正有效的方法(toxhr
和xdr
)?
var xhr = new XMLHttpRequest(); // Or var xdr = new XDomainRequest
...
xhr.open("get", "//mydomain.com/api/v1/etc", true);
...
或者
var xhr = new XMLHttpRequest();
...
xhr.open("get", window.location.protocol + "//mydomain.com/api/v1/etc", true);
...
或者..还有什么?
注意:Making a protocol agnostic jquery ajax call的问题没有提到这两种情况XMLHttpRequest
,XDomainRequest
也没有提供经过验证的解决方案。