次のコードはFirefoxでうまく動作しますが、Google ChromeとSafariのメソッドdoc.documentElement.innerHTML
ではundefined
が返されます。文字列(またはhttp応答を文書に変換する別の方法)から文書を作成する別の方法はありますか?相当するdocument.implementation.createDocument()がありますか?このメソッドはGoogle ChromeとSafariで未定義を返すので
var url = "/myapp/ajax";
http = getHttpObject();
http.open("POST", url, true);
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", dropdownId.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200){
var doc = document.implementation.createDocument ('http://www.w3.org/1999/xhtml', 'html', null);
//This seems to return undefined
doc.documentElement.innerHTML = http.responseText;
console.log(doc);
}
}
ここにいくつかの情報:http://reference.sitepoint.com/javascript/DOMImplementation/createDocument – techfoobar
ああ、私ははdocument.firstChildはChromeとSafariでnullを返すが、他のどのような方法であることを見ます(document.getElementById( 'foo')でデータを取得できるように)http://responseTextをドキュメントに入れます。 – mvdb