2011-12-27 5 views
0

次のコードは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); 
     } 
    } 
+1

ここにいくつかの情報:http://reference.sitepoint.com/javascript/DOMImplementation/createDocument – techfoobar

+0

ああ、私ははdocument.firstChildはChromeとSafariでnullを返すが、他のどのような方法であることを見ます(document.getElementById( 'foo')でデータを取得できるように)http://responseTextをドキュメントに入れます。 – mvdb

答えて

1
  1. これは、任意の関心があるかもしれませんか?

http://dean.edwards.name/weblog/2006/04/easy-xml/

+0

XMLドキュメントではなく、返された文字列からHTMLドキュメントを作成しようとしています。今、私はちょうどajaxリクエストでデータを取得する代わりに、javascriptのformubmitを実行します。 – mvdb

関連する問題