vaneetagoswami
New member
- Joined
- Mar 6, 2014
- Messages
- 370
- Points
- 0
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
This is the code for getdata js file
and at last the name php file code is below
Here file name config php used to connect with database
index php file code
Code:
<!DOCTYPE html>
<html>
<head>
<title>Ajax Demo</title>
</head>
<body>
Name: <input type="text" name="name" id="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>
Code:
$('input#name-submit').on('click', function(){
var name = $ ('input[name="name"]').val();
if($.trim(name) != ''){
$.post('name.php', {name: name}, function(data) {
$('div#name-data').text(data);
});
}
});
Code:
$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' ;
}
?>