Skip to content

Instantly share code, notes, and snippets.

@serebrov
Last active January 25, 2016 11:40
Show Gist options
  • Save serebrov/6e8fa5312f80c9d53102 to your computer and use it in GitHub Desktop.
Save serebrov/6e8fa5312f80c9d53102 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test ajax</title>
</head>
<body>
<script>
function showCat(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","getcat.php?q="+str,true);
xmlhttp.send();
}
}
</script>
<table>
<tr>
<td>
<div>
<a onclick="showCat('95')">showCat('95')</a>
<a onclick="showCat('23')">showCat('23')</a>
<a onclick="showCat('55')">showCat('55')</a>
<a onclick="showCat('65')">showCat('65')</a>
</div>
</td>
</tr>
<tr>
<td>
<div id="txtHint">
</div>
</td>
</tr>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment