Mari kita perhatikan gambar berikut
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>AJAX</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<h1> jQuery AJAX</h1>
<p id="id_div_keterangan">Paragraf ini akan terisi konten dari file external</p>
<button>Klik</button>
<script>
$(document).ready(function(){
$("button").click(function(){
ambil_data_ajax();
});
});
function ambil_data_ajax()
{
let request_data_ajax = jQuery.ajax({
url:"file_luar.html",
type : 'POST',
datatype:'text',
timeout: 20000,
data:{}
});
request_data_ajax.done(function(output)
{
//jQuery("#id_div_keterangan").load("file_luar.html" );
jQuery("#id_div_keterangan").html(output)
});
request_data_ajax.fail(function(jqXHR, textStatus)
{
});
}
</script>
</body>
</html>