Dojo - iframe 抓取传入的 html



我想用"dojo/request/iframe"向其他域发送帖子请求(我使用它是因为dojo.xhrPost不起作用,besause重定向)。在网站响应之后,我想获取收入 html(我在 Firebug 中看到该 html 作为对 iframe 请求的响应)。我该怎么做?

你可以像使用xhr一样使用它。

require(["dojo/request/iframe"], function(iframeRequest) {
    iframeRequest.post("/your/url", {
        handleAs: "html"
    }).then(function(response) {
        document.getElementById("result").appendChild(
            response.childNodes[0]);
    });
});

请记住,当您使用 handleAs:"html" 时,response 是一个Document对象,因此您必须如上所述访问其childNodes

http://dojotoolkit.org/reference-guide/1.9/dojo/request/iframe.html

最新更新