Refresh content halaman secara ajax dengan fungsi load


untuk meload atau menambahkan isi dari suatu halaman lain kedalam halaman kita secara ajax dapat digunakan fungsi load pada jquery

misal kita punya 2 halaman a.php dan b.php

kita akan meload/memasukkan  isi halaman b.php kedalam a.php secara ajax

save sebagai a.php

  <!DOCTYPE html>
<html>
<head>
  <style>
  body{ font-size: 12px; font-family: Arial; }
  </style>
  <script src="../jquery-1.4.1.min.js"></script>
</head>
<body>
  
<b>Successful Response (should be blank):</b>
<div id="success"></div>
<b>Error Response:</b>
<div id="error"></div>
  
<script>
$("#success").load("http://localhost/jquery/load/not-heire.php", function(response, status, xhr) {
  if (status == "error") {
    var msg = "Sorry but there was an error: ";
    $("#error").html(msg + xhr.status + " " + xhr.statusText);
  }
});
  </script>

</body>
</html>

save sebagai b.php

<?php
echo "hasil loading";
//echo site_url();
?>

tinggalkan pesan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d blogger menyukai ini: