Actually I am trying to get the data without refreshing the page. The below are the coding which I done for this.
Here file name config php used to connect with database
index php file code
<!DOCTYPE html>
<html>
<head>
<title>Ajax Demo</title>
</head>
<body>
Name: <input type="text" name="name"/><br />
<input type="submit" name="name" id="name-submit" value="Get Data"/>
<div id="name-data"></div>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="js/getdata.js" ></script>
</body>
</html>
This is the code for getdata js file
$('input#name-submit').on('click', function(){
var name = $ ('input#name').val();
if($.trim(name) != ''){
$.post('name.php', {name: name}, function(data) {
$('div#name-data').text(data);*/
});
}
});
and at last the name php file code is below
$query = mysqli_query($con, "SELECT *
FROM `temp`
WHERE `name`.`name`='". mysqli_real_escape_string(trim($_POST['name'])) ."'");
$num = mysqli_num_rows($query);
echo ($num !== 0) ? mysqli_result($query, 0, 'lastname') : 'Name Not Forund' ;
}
?></code>