初学Ajax书中有这样一个例子:var XMLHttp=new ActiveXObject('Microsoft.XMLHTTP');
XMLHttp.open('GET','http://localhost/books.XML',false);
XMLHttp.send();
alert(XMLHttp.responseBody);但是Error:类型不匹配。我只知道responseBody返回的结果是二进制的,哪位高手来帮我解释一下
XMLHttp.open('GET','http://localhost/books.XML',false);
XMLHttp.send();
alert(XMLHttp.responseBody);但是Error:类型不匹配。我只知道responseBody返回的结果是二进制的,哪位高手来帮我解释一下
2. responseBody返回的结果是二进制? 谁说的?
<html>
<head><title>Base64 Convert</title></head>
<body>
<table style="width:100%;">
<tr style="height:25px">
<td>URL:</td>
<td style="width:90%;"><input id="text_url" style="width:60%;" type="text" value="http://pages.anjukestatic.com/img/comm/commstar.gif" onkeydown="if(event.keyCode==13)btnConvert.click()" onfocus="this.select();"/><input type="button" value="Generate Base64" id="btnConvert" onclick="buttonBase64_Click()"/></td>
</tr>
<tr style="height:300px;">
<td>BASE64:</td>
<td><input type="button" value="Copy Base64 Data As SRC" onclick="copy()"/><span id="copyInfo" style="color:#F00;margin-left:20px;"></span><br/><textarea id="textarea_base64" style="width:100%; height:100%" /></textarea></td>
</tr>
<tr style="height:80px;">
<td>ResponseHeaders:</td>
<td><textarea id="textarea_responseHeaders" style="width:100%; height:100%" /></textarea></td>
</tr>
<tr>
<td>Preview:</td>
<td id="img"></td>
</tr>
</table>
</body>
<script>
//http://topic.csdn.net/u/20100127/14/a961df9a-34a1-44f1-9f9a-c10a4d168736.html
var src="",header="";
function buttonBase64_Click() {
var x = new ActiveXObject("MSXML2.XMLHTTP");
x.open("GET", text_url.value, false);
x.send(null);
if (x.status == 200) {
headers=x.getAllResponseHeaders();
textarea_responseHeaders.value = headers;
with (new ActiveXObject("MSXML2.DOMDocument").createElement("node")) {
dataType = "bin.base64";
nodeTypedValue = x.responseBody;
textarea_base64.value = text;
src="data:"+headers.match(/Content-Type:\s*([^\s]+)/)[1]+";base64,"+ text;
//src="data:image/jpeg;base64,"+ text;
img.innerHTML="<img src='"+src+"'/>";
}
} else {
textarea_base64.value = textarea_responseHeaders.value = '';
}
}
function copy(){
window.clipboardData.setData("Text",src);
copyInfo.innerHTML="Data copyed!";
setTimeout(function(){
copyInfo.innerHTML="";
},3000);
}
</script>
</html>
responseText 是文本字符串
responseXML 是 XML Document 对象
XMLHttp.open('GET','http://localhost/book.XML',false);
XMLHttp.send();
var XMLDoc=new ActiveXObject('Microsoft.XMLDOM');
var x=XMLDoc.createElement('node');
x.dataType='bin.base64';
x.nodeTypedValue=XMLHttp.responseBody;
alert(x.text);以下这样就能输出了,输出的应该是base64编码吧然后,我把bin.base64改成bin.hex,输出了十六进制,而直接输出responseBody就会出现类型不匹配的问题。
我现在大概是明白了responseBody的用法