2016-04-10 22 views
-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> 
+1

コンソールを追加することができます。 log(el); after var el = document.getElementById( "content"); – Ygalbel

+0

問題がセレクタかhtml関数かどうか確認できます – Ygalbel

+0

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"); }) –

答えて

1

.html()はjquery関数です。

あなたはコードだ innerHTMLのフィールド

設定する必要がjavascriptのバニラのHTMLテキストを変更するには:

document.getElementById(id).innerHTML = new HTML 

参照:

http://www.w3schools.com/js/js_htmldom_html.asp

関連する問題