Contoh Script Ajax Sederhana

  • Uploaded by: Mas Yudi
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Contoh Script Ajax Sederhana as PDF for free.

More details

  • Words: 293
  • Pages: 4
demo.html Demo Ajax <script type="text/javascript" src="demo.js">
Nama:
Hasil Respon
demo.js function buatXmlHttpRequest(){ var req=false; if(window.ActiveXObject){ //ms ie try{ req=new ActiveXObject("MicrosoftXMLHTTP"); }catch(e){ req=false; } }else{ //pake mozilla, opera dll try{ req=new XMLHttpRequest(); }catch(e){ req=false; } } return req; } var xmlhttp=buatXmlHttpRequest(); function proses(){ if(xmlhttp.readyState==0||xmlhttp.readyState==4){ var v_nm=document.getElementById('nama').value; var url="http://localhost/08510107/demo.php?nm="+v_nm; xmlhttp.open("GET",url,true); xmlhttp.onreadystatechange=responku; xmlhttp.send(null); } } function responku(){ if(xmlhttp.readyState==4){ if(xmlhttp.status==200){ var hasil=xmlhttp.responseText; document.getElementById("hasil").innerHTML=hasil; } } } demo.php
if(!empty($nm)){ echo"Selamat Datang,$nm!"; } ?> demo.js dengan timer function buatXmlHttpRequest(){ var req=false; if(window.ActiveXObject){ //ms ie try{ req=new ActiveXObject("MicrosoftXMLHTTP"); }catch(e){ req=false; } }else{ //pake mozilla, opera dll try{ req=new XMLHttpRequest(); }catch(e){ req=false; } } return req; } var xmlhttp=buatXmlHttpRequest(); function proses(){ if(xmlhttp.readyState==0 || xmlhttp.readyState==4){ var nm=document.getElementById("nama").value; var url="http://localhost/ajax/masyud/demo.php?nm="+nm; xmlhttp.open("GET",url,true); xmlhttp.onreadystatechange=respon; xmlhttp.send(null); } else{ setTimeout("proses()",1000); } } function respon(){ if(xmlhttp.readyState==4){ if(xmlhttp.status==200){ var hasil=xmlhttp.responseText; document.getElementById("hasil").innerHTML=hasil; } } else{ setTimeout("proses()",1000); } } With MySQL database demo.js function buatXmlHttpRequest(){

var req=false; if (window.ActiveXObject){ try{ req=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ req=false; } }else{ try{ req=new XMLHttpRequest(); }catch(e){ req=false; } } return req; } var xmlhttp = buatXmlHttpRequest(); function proses(){ if (xmlhttp.readyState == 0 || xmlhttp.readyState==4){ var k=document.getElementById('kunci').value; var url= "http://localhost/internet3/tamu.php?kunci="+k; xmlhttp.open("GET", url, true); xmlhttp.onreadystatechange = respon; xmlhttp.send(null); } } function respon(){ if(xmlhttp.readyState == 4){ if (xmlhttp.status == 200){ var hasil=xmlhttp.responseText; document.getElementById('hasil').innerHTML=hasil; } } } tamu.php "; echo "\n"; echo "\n"; //akses ke database test dan tabel tamu $id=mysql_connect("localhost","root", "") or die("Gagal koneksi ke server DB!"); mysql_select_db("test", $id) or die("Gagal mengaktifkan database test!"); $sql="SELECT email, nmtamu FROM tamu "; if (isset($_GET['kunci'])){ $k=$_GET['kunci']; $sql="SELECT email, nmtamu FROM tamu ";

$sql = $sql . " WHERE email LIKE '%$k%' "; } $hasil=mysql_query($sql, $id); while ($baris=mysql_fetch_row($hasil)){ echo "\n"; echo "<email>$baris[0]\n"; echo "$baris[1]\n"; echo "\n"; } echo "
\n"; ?>

Related Documents

Ajax
December 2019 56
Ajax
May 2020 36
Ajax
June 2020 25
Ajax
May 2020 28

More Documents from ""