【发布时间】:2014-11-30 21:36:33
【问题描述】:
我通过以下方式成功发送了XMLHttpRequest:
var createCORSRequest = function(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Most browsers.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// IE8 & IE9
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
};
var url = 'http://www.whatismyip.com';
var method = 'GET';
var xhr = createCORSRequest(method, url);
xhr.onload = function() {
// Success code goes here.
};
xhr.onerror = function() {
// Error code goes here.
};
xhr.setRequestHeader('referer', 'http://www.google.com');
xhr.send();
但是,我无法定义我的referer。添加自定义referer的正确方法是什么?
【问题讨论】:
-
我有同样的问题,不明白为什么 XMLHttpRequest 没有推荐人或用户代理信息?有没有办法使用 fetch 或 axios 来捕获它们?
标签: javascript jquery ajax internet-explorer