Good day! There is a search form:
<form method="POST" action="simple_search.php" id="form_id" enctype="multipart/form-data"> <input type="text" name="usersearch" size="50" /> <input type="submit" name="submit" value="Искать" id="submit" /> </form> And a div to display the results:
<div id="result></div> Ajax sends a request to the php handler:
$("#submit").click(function(e) { var $form = $("#form_id"); $.ajax({ cashe: false, type: $form.attr('method'), url: $form.attr('action'), data: $form.serialize(), }).done(function() { console.log('success'); }).fail(function() { console.log('fail'); }); e.preventDefault(); }); The handler searches the database and displays the results
$user_search = $_POST['usersearch']; if(!empty($user_search)) { $query_usersearch = "SELECT * FROM docs WHERE title LIKE '%$user_search%' OR description LIKE '%$user_search%' OR keywords LIKE '%$user_search%'"; $result_usersearch = mysqli_query($link, $query_usersearch); while($array_usersearch = mysqli_fetch_array($result_usersearch)) { echo $array_usersearch['title']; echo $array_usersearch['description']; } } Question: how to put these results using the same ajax request in the #result div? Thank!