jquery ajax loading code example

Example 1: ajax load spesific element from another page

$.ajax({
   url:href,
   type:'GET',
   success: function(data){
       $('#container').html($(data).find('#content').html());
   }
});

Example 2: ajax load spesific element from another page

$('#container').load('ajax/test.html #content');

Example 3: jquery load php

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>load demo</title>
  <style>
  body {
    font-size: 12px;
    font-family: Arial;
  }
  </style>
  <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
 
<b>Projects:</b>
<ol id="new-projects"></ol>
 
<script>
$( "#new-projects" ).load( "/resources/load.html #projects li" );
</script>
 
</body>
</html>

Tags:

Php Example