My situation is as follow, i have a form input in a Jquery Mobile page, and i am submitting the form with no form button. I need the returned result from the php(it is in JSON) back in the html. But at the moment when i submit the search with pressing the enter button, it links to the php page, with the returned results and just stuck there, and not back in the html page. Thanks for your time!
Code:
$("#searchform").submit(function( event ) {
$.ajax({
type: "GET",
url: "http://test.com/App/searchtest.php",
dataType:'json',
success: function(data){
console.log(data);
$("#content").append(data);
}
})
});
<form id="searchform" name="searchform" method="post"
action="http://www.test.com/App/searchtest.php" data-ajax="false">
<input type="search" id="searchinput" name="searchterm"
value="" data-mini="true" placeholder="Where?"/>
</form>
<?php
ini_set('display_errors', 1); error_reporting(E_ALL);
include 'connect.php';
$search = ($_POST['searchterm']);
$keywords = explode (" ", $search);
$columns = array("country","name");
$andParts = array();
foreach ($keywords AS $keyword){
$orParts = array();
foreach($columns AS $column){
$orParts[] = $column . " LIKE '%" . ($keyword) . "%'";
}
$andParts[]= "(" . implode($orParts, " OR ") . ")";
}
$and = implode ($andParts, " AND ");
$sql = "SELECT * FROM Listing WHERE $and ";
$result = mysqli_query($con,$sql);
$output = array();
// fetch your results
while( $row = mysqli_fetch_assoc($result)) {
// add result row to your output's next index
$output[] = $row;
}
// echo the json encoded object
echo json_encode( $output );
?>
phpfor us to look at. Also, check your browser consolenetworktab to see the response from the server. It will most likely tell you what is going onphpcodef12), it will show the error