18
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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)を作成する必要がありますが、楽です。

では、参考までに

18
22
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
18
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?