How to do a Load with jQuery and Ajax for a DIV?

0

Hello good afternoon I have this code but I know how to make the Div actulize with your example ID this div is to see the data in the .php file

 <div id="album_paint_content"></div>

and these images in ID have the post that I want to see

  

album_content ID

<img id="album_content1" class="img_thumbnails" src="imagen"/>
<img id="album_content2" class="img_thumbnails" src="imagen"/>
<img id="album_content3" class="img_thumbnails" src="imagen"/>
<img id="album_content4" class="img_thumbnails" src="imagen"/>

here is the js to do that but I do not know how to do that from an ID because only the first is actuzlized but the others do not

$(document).ready(function(){   
            $('#album_content').click(function(){
                $("#album_paint_content").load("paint_new.php");
            });
        }); 

Well I hope you help me and thank you

    
asked by Shareiv 24.10.2017 в 23:50
source

1 answer

0

You can do it like this:

$( "#album_paint_content" ).load( "paint_new.php .img_thumbnails") ...

That way you get only those elements whose class is img_thumbnails .

If you want all the content of the page you remove that and that's it.

Here is an example, implementing error handling.

We will get the elements whose class is title on this MDN page.

$(function()  //document.ready es  obsoleto a partir de jQuery 3
{
  $('#album_content').click(function() 
  {
      var url_elem="https://developer.mozilla.org/en-US/docs/Web/HTML .title";
     
      $("#album_paint_content").load(url_elem, function(response, status, xhr) 
      {
          if (status == "error") {
            var msg = "Hubo un error: ";
            console.log(msg + xhr.status + " " + xhr.statusText);
       }
      });
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="album_content">Cargar contenido...</button>
<hr />
<div id="album_paint_content"></div>
    
answered by 25.10.2017 в 00:12