function loaded() {
var xmldoc,
currenttime = new Date().getTime(),
req,
address = 'http://webservices.foo.com/eSignalQuotes/eSignalQuotes.asmx/GetDelayedQuotes?',
symbols = 'symbols=' + '+c,s,ct,zw,kw,adm+',
cusip = '&cusip=',
fields = '&fields=' + 'desc,month,year,recent,netchg,-decimal',
type = '&type=' + 'future,stock,index',
dispfullname = '&dispfullname=' + 'true',
datefmt = '&datefmt=',
timefmt = '&timefmt=',
timestamp = '&' + Math.floor(currenttime/3600000),
query = address + symbols + cusip + fields + type + dispfullname + datefmt + timefmt + timestamp;
;
if(window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.addEventListener('error', function(e) {alert('Error');}, false);
req.addEventListener('load', function(e) {xmldoc = req.responseText;}, false);
req.open('GET', query, true);
req.send();
}
这就是我的代码的样子,它总是在 Safari 和 Firefox 中引发错误。疯狂的是,如果我删除事件侦听器,并将响应类型更改为responseText
,Internet Explorer 会给我输出。我试过overrideMimetype
了,但这似乎没有帮助。如果我在 Firefox 或 Safari 中检查响应,我会得到null
. 我很茫然,任何帮助将不胜感激。
我应该提到,我宁愿为此避免任何 3rd 方库。
更新:错误发生在progress
事件期间,如果我检查.lengthComputable
我得到false
更新 2:Safari 更清楚地说明了这个问题:
XMLHttpRequest cannot load Origin is not allowed by Access-Control-Allow-Origin.