Wednesday, 13 December 2017

Ajax

HI All,

Program 1 - ajaxmain.php
----------------------
<html>
<head>
<script>
function loadDoc() {
//alert('HUP');
     var

key=document.frmsearch.sname.value;
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange =

function() {
        if (xhttp.readyState == 4 &&

xhttp.status == 200) {
             document.getElementById

("demo").innerHTML = xhttp.responseText;
        }
  };
  xhttp.open("GET", "searchstud.php?

key="+key, true);
  xhttp.send();
}
</script>


</head>
<body >
<form name=frmsearch  method=post>
<center>Name <input type=text name=sname

onkeyup="loadDoc()"><input type=button

value='Search Student'onclick="loadDoc

()">
</center>
</form>
<div id="demo" align=center><h2>Search

Result</h2></div>
</body>
</html>


-----------------------
Program 2 - searchstud.php

<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("m301db",$con);
$sname=$_GET['key'];

$sql="Select * from tbl_student where st_name like '%$sname%'";



$data=mysql_query($sql,$con);
echo "<table border=1 align=center width=50%>";
echo "<tr><th>Name</th><th>Roll No</th><th>Marks</th></tr>";
while($row=mysql_fetch_array($data))
{
$name=$row[0];
$rollno=$row[1];
$marks=$row[2];

echo "<tr><td>$name</td><td>$rollno</td><td>$marks</td></tr>";

}

mysql_close($con);

?>

9 comments:

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. This comment has been removed by the author.

      Delete
    4. This comment has been removed by the author.

      Delete
  4. This comment has been removed by the author.

    ReplyDelete