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
Recommended threads
Replies
15
Views
12,736
Replies
4
Views
3,654
Replies
3
Views
1,243
Replies
5
Views
3,351

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