Skip to content

Instantly share code, notes, and snippets.

@bertzzie
Created December 30, 2012 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bertzzie/4413020 to your computer and use it in GitHub Desktop.
Save bertzzie/4413020 to your computer and use it in GitHub Desktop.
Contoh AJAX pada <a>
index.php
<html>
<head>
<title>AJAX test</title>
<script type="text/javascript">
function func() {
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200) {
document.getElementById("isian").innerHTML = httpRequest.responseText;
} else {
alert('There was a problem with the request.');
}
}
};
httpRequest.open('GET', "http://localhost/ajaxtest/aboutus.php");
httpRequest.send();
return false;
}
</script>
</head>
<body>
<h1>Testing AJAX</h1>
<p>Ini testing link saja. <a href="#" onclick="return func()">About</a>
<div id="isian"></div>
</body>
</html>
aboutus.php
<h2>About Us</h2>
<p>Lorem ipsum dolor sit amet</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment