php - Ajax can't load the data -
actually trying data without refreshing page. below coding done this.
here file name config php used connect 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 code 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 @ last name php file code below
$query = mysqli_query($con, "select * `temp` `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>
i can't see input id="name"! var name = $ ('input#name').val();
can fix using code : var name = $ ('input[name="name"]').val();
Comments
Post a Comment