Can't get value from Ajax

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

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>
This is the code for getdata js file

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);
        });
    }
});
and at last the name php file code is below

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' ;
}
?>
 

freds86

Member
Joined
Mar 13, 2014
Messages
85
Points
8
jQuery $.post() or $.get() Method is

$.get(URL,callback);

$.post(URL,data,callback);
where is your function(data)????

you missed this function, I didn't see it in name.php file (result page)

Although you called it

$.post('name.php', {name: name}, function(data)

but result was not returned with this function.

Check that.
 
Older threads
Latest threads
Replies
0
Views
591
Replies
2
Views
791
Recommended threads
Replies
6
Views
3,912
Replies
4
Views
876
Replies
5
Views
4,045
Replies
1
Views
1,334

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top