Advertisement
GWibisono

menampilkan gambar

Dec 13th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.43 KB | None | 0 0
  1. <html>
  2.   <head>
  3.     <meta name="generator"
  4.    content="HTML Tidy for HTML5 (experimental) for Windows https://github.com/w3c/tidy-html5/tree/c63cc39" />
  5.     <title>Menampilkan Gambar dengan Ajax</title>
  6.     <style>
  7.     .box{
  8.         min-width:60px;
  9.         min-height:40px;
  10.         max-width:200px;
  11.         max-height:200px;
  12.         border: 1px blue solid;
  13.         margin:5px;
  14.         padding:5px;
  15.     }
  16.     </style>
  17.   </head>
  18.   <body>
  19.  
  20.     <h1>Menampilkan Gambar (Ajax)</h1>
  21.     <p>Pada kotak dibawah, tidak terdapat gambar. Pilihlah select yang tersedia</p>
  22.     <div class='box'></div>
  23.     <select onclick='loadImage(this)' >
  24.     <option>Pilih dari gambar tersedia</option>
  25.       <option value='001.jpg'>Gambar Pertama</option>
  26.       <option value='002.jpg'>Gambar Kedua</option>
  27.       <option value='003.jpg'>Gambar Ketiga</option>
  28.       <option value='tidak ada.jpg'>Gambar Tidak Tersedia</option>
  29.       <option value='005.jpg'>Gambar Kelima</option>
  30.     </select>
  31.     <script src='script/jquery-1.9.min.js' ></script>
  32.     <script>
  33.     function loadImage(p){
  34. //=================
  35.         val= $(p).val();
  36.         dataJson = {name:val}
  37.        
  38.           var request = $.ajax({
  39.            url: "show_image.php",
  40.            type: "POST",
  41.            data: dataJson,
  42.            dataType: "json"
  43.             });
  44.          
  45.         request.success(function(result) {
  46.           $(".box").html( result.html );
  47.          });
  48.          
  49.         request.fail(function(jqXHR, textStatus) {
  50.           alert( "Request failed: " + textStatus );
  51.          });
  52.     }
  53.     </script>
  54.   </body>
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement