【发布时间】:2010-12-28 23:47:17
【问题描述】:
我正在尝试使用 Ajax (XMLHttpRequest) 下载 Excel 文件。
完成后,responseText 仅包含 5 个字符。
网络嗅探工具 (Fiddler) 显示我的计算机收到了整个文件..
那么为什么 responseText 只显示 5 个字符?我已经尝试过同步和异步调用。
感谢您在此处提供的任何帮助。
var xmlHttpReq = getXmlHttpRequestObject();
function getXmlHttpRequestObject(){
var xmlhttp;
if (window.XMLHttpRequest){// code for all new browsers
xmlhttp=new XMLHttpRequest();
}else if (window.ActiveXObject){// code for IE5 and IE6
// xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
progids = ['MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.3.0', 'Microsoft.XMLHTTP'];
for (i=0 ; i < progids.length; i ++){
try {
xmlhttp = new window.ActiveXObject(progids[i]);
break;
} catch (e) {
//do nothing
}
}
}
return xmlhttp;
}
//utility method for http get
function doSynchronousGet(url){
if(xmlHttpReq == null){
xmlHttpReq = getXmlHttpRequestObject();
}
//change last param to true for making async calls.
xmlHttpReq.open("GET" ,url,false);
xmlHttpReq.setRequestHeader("Connection", "close");
xmlHttpReq.send(null);
return xmlHttpReq.responseText;
}
var resultText = doSynchronousGet(url);
alert('resultText length: '+ resultText.length);
alert('resultText: '+ resultText);
【问题讨论】:
标签: ajax xmlhttprequest download