Slip 28 - A) Write an Ajax program to display list of games stored in an array on clicking OK button.

Solution:

Html file -

<html>
<head>
<script >
function dis()
{
var ob=false;
ob=new XMLHttpRequest();
var gm=document.getElementById("gm").value;
ob.open("GET","slip27.php?game="+gm);
ob.send();
ob.onreadystatechange=function()
{
if(ob.readyState==4 && ob.status==200)
{
document.getElementById("game").innerHTML=ob.responseText;
}
}
}
</script>
</head>
<body>
<h2>Display the list of Games<input type=button name=submit value=OK id="gm" onClick="dis()"></h2>
<span id="game"></span>
</body>
</html>


Php file -

<?php
$gm=$_GET['game'];
$a=array("Hockey","Football","Cricket","Basket Ball","Kho-Kho","Tennis","Dough Ball");
echo "<h3>List of Games
</h3>";
for($i=0;$i {
echo $a[$i]."<br>";
}
?>

Post a Comment

0 Comments