Selasa, 10 April 2012

GET Request menggunakan AJAX

Letakkan script ini sebelum </header>

 < script type="text/javascript">

function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
 if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
  for (var i=0; i<activexmodes.length; i++){
    return new ActiveXObject(activexmodes[i])
    //suppress error
 else if (window.XMLHttpRequest) // if Mozilla, Safari etc
  return new XMLHttpRequest()
  return false

<script type="text/javascript">

function ajaxget(){
var mygetrequest=new ajaxRequest()
if (mygetrequest.readyState==4){
if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){
alert("An error has occured making the request")
var namevalue=encodeURIComponent(document.getElementById("name").value)
var poinvalue=encodeURIComponent(document.getElementById("poin").value)"GET", "tujuan.php?name="+namevalue+"&poin="+poinvalue, true)



Letakkan Form ini pada bagian </body>

<form method="get" action="">
Your name: <input type="text" id="name" name="name" size="25" /> <br />
Your age: <input type="text" id="age" name="age" size="25" /> <br />
<input type="button" value="submit" onClick="ajaxget()" />

<div id="result"> </div>

buat file baru dengan nama tujuan.php

echo "<span style='color:red'>Welcome <b>$name</b> to JavaScript Kit. So you're <b>$age</b> years old eh?</span>";
◄ Newer Post Older Post ►