LoginSignup
17
21

More than 5 years have passed since last update.

ajaxで外部htmlを読み込む方法 メモ

Last updated at Posted at 2017-05-18

簡単で、拡張もしやすいかと思い、メモ。


    function 関数名(){
      $.ajax({
          url : 'parts.html',
          dataType : 'html',
          success : function(data){
              $('#要素').html(data);//A
          },
          error: function(data){
              $('#要素').html(data);//A
          }
      });
    }

もちろん、読み込みたいファイルの方で、scriptを読み込んで、その中でもpartsを実行します。

<script type="text/javascript">関数名();</script>
<div id="要素"></div>


こちらが、Aの部分です。
別で、読み込ませたいファイル(html)を作成する必要がありますが、楽です。

では、参考までに

17
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
21