-1
私はreqwestライブラリを使用してレスポンスを読み込み、jquery(ここでは大きすぎます)を避けたいと考えています。.htmlはreqwest.jsライブラリのある関数ではありません
しかし、私が "el"をjquery $( "#content")に変更した場合、document.getElementByIdは.load呼び出しに受け入れられないようです。これを処理するために、el.html(resp)部分をどのように書き直すべきですか?
reqwestの例ではセレクタに "qwery"ライブラリが使用されていますが、これは避けたい別の10kbです。アイデアありがとう!
<script type="text/javascript" src="https://private_path_to_s3/reqwest.min.js"></script>
<!--Content-->
<div id="content">Empty!</div>
<script type="text/javascript">
reqwest('http://localhost:3000/iframe?keyword=XXXXX', function (resp) {
var el = document.getElementById("content");
//Replace the content with the response
el.html(resp);
//rename the div to avoid refiring
el.setAttribute("id", "ks-content-loaded");
})
</script>
コンソールを追加することができます。 log(el); after var el = document.getElementById( "content"); – Ygalbel
問題がセレクタかhtml関数かどうか確認できます – Ygalbel
console.log(el)トリックのおかげで、まだ分かりませんでした。私は下のあなたの提案でそれを解決するのに役立ちました。最終コードは次のとおりです:reqwest( 'http:// localhost:3000/iframe?キーワード= XXXXX'、function(resp){ var el = document.getElementById( "ks-content"); //コンテンツをレスポンス el.innerHTML = resp; //リビジョンを避けるためにdivの名前を変更します。 el.setAttribute( "id"、 "ks-content-loaded"); }) –