Can't get value from Ajax

vaneetagoswami

Well-known member
Registered
Joined
Mar 6, 2014
Messages
140
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
Registered
Joined
Mar 13, 2014
Messages
49
Points
0
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
Replies
1
Views
2,887
Replies
11
Views
5,124
Replies
1
Views
3,055
Latest Threads
Replies
1
Views
26
Replies
0
Views
188
Replies
1
Views
40
Replies
2
Views
83

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

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