我刚刚看了 YUI3 的源代码。在https://raw.github.com/yui/yui3/master/src/io/js/io-upload-iframe.js中负责请求对象的几行是:
_uploadComplete: function(o, c) {
var io = this,
d = Y.one('#io_iframe' + o.id).get('contentWindow.document'),
b = d.one('body'),
p;
if (c.timeout) {
io._clearUploadTimeout(o.id);
}
try {
if (b) {
// When a response Content-Type of "text/plain" is used, Firefox and Safari
// will wrap the response string with <pre></pre>.
p = b.one('pre:first-child');
o.c.responseText = p ? p.get('text') : b.get('text');
Y.log('The responseText value for transaction ' + o.id + ' is: ' + o.c.responseText + '.', 'info', 'io');
}
else {
o.c.responseXML = d._node;
Y.log('The response for transaction ' + o.id + ' is an XML document.', 'info', 'io');
}
}
catch (e) {
o.e = "upload failure";
}
io.complete(o, c);
io.end(o, c);
// The transaction is complete, so call _dFrame to remove
// the event listener bound to the iframe transport, and then
// destroy the iframe.
w.setTimeout( function() { _dFrame(o.id); }, 0);
},
因此,只要响应包含“正文”节点,它就会将正文内容作为“文本”返回。
o.c.responseText = p ? p.get('text') : b.get('text');
恕我直言,如果有 body 节点,就没有机会获得 innerHTML。我决定创建一个自定义的 IO Upload Iframe 模块,该模块添加了一个名为“responseHTML”的附加属性,以及 body 节点的 innerHTML。
您可以从 Pastebin 获取源代码:http: //pastebin.com/WadQgNP2