Insert a Div from another page

Asked

Viewed 504 times

0

I’m trying to catch a DIV of this page .

To DIV is named after .similar-artists. I want to play in the DIV calling for #rock, but nothing works. Below the code:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
	
 $("#rock").load("http://pipocaplayfm.com/artist/5216/Calvin+Harris .similar-artists ");
	
	 });
	
</script>

</head>
<body>
 
<div id="rock">
	
</div>
   
  </body>
</html>

  • You are developing a website as a static page, using HTML ONLY or are developing dynamically, with Javaee, PHP, Javascript?

  • @Dynamic tiagoboeing with javascript and php. I just need to understand how I make it work $("#div1"). load("demo_test.txt #P1"); as in link : https://www.w3schools.com/jquery/jquery_ajax_load.asp

  • You can do this using PHP itself.

1 answer

1


Try it that way..

$.ajax({
    url: 'http://pipocaplayfm.com/artist/5216/Calvin+Harris',
    success: function(res){
                        $(res.responseText).find('.similar-artists')each(function(){
            $('#app').append($(this).html())
        
        });
    }
})
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
    <div id="app"></div>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
    
</body>
</html>

  • the Ajax part I put everything on the same page ? I copied and pasted on my page here and only when I update it shows the ajax code and not the content. I need to put on something else or do ?

  • I did everything as it is , but it doesn’t work

  • Unable to pull content from another site via Ajax due to CORS.

  • @jhonatansantos I tested here and it was as the friend above spoke, the site is blocking, so due to the CORS, it is not possible to pull the content.

  • @Rafaelaugusto there is some way I can disable this CORS you quoted ??

Browser other questions tagged

You are not signed in. Login or sign up in order to post.