Я пытаюсь добиться Ajax Live Data Search в MongoDB, используя Jquery + PHP.
, поэтому я следую этому руководству и пытался преобразовать его, чтобы он работал с MongoDB.
index.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax Live Data Search using Jquery PHP MONGODB</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="container">
<br />
<br />
<br />
<h2 align="center">Ajax Live Data Search using Jquery PHP MONGODB</h2><br />
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">Search</span>
<input type="text" name="search_text" id="search_text" placeholder="Search by Customer Details" class="form-control" />
</div>
</div>
<br />
<div id="result"></div>
</div>
<div style="clear:both"></div>
<br />
<br />
<br />
<br />
</body>
</html>
<script>
$(document).ready(function(){
load_data();
function load_data(query)
{
$.ajax({
url:"fetch.php",
method:"post",
data:{query:query},
success:function(data)
{
$('#result').html(data);
}
});
}
$('#search_text').keyup(function(){
var search = $(this).val();
if(search != '')
{
load_data(search);
}
else
{
load_data();
}
});
});
</script>
fetch.php
<?php
require 'vendor/autoload.php';
$output = '';
if(isset($_POST["query"]))
{
$search = $_POST["query"];
echo $search;
}
else
{
// the array of product criteria
$client = new MongoDB\client;
$userDB = $client->AW;
$profilecollection = $userDB->DA1;
$query = $profilecollection->find(array(),array("full_name"=>1));
foreach($query as $result)
{
//echo $result['Author'];
$output .= '<div class="table-responsive">
<table class="table table bordered">
<tr>
<th>Customer Name</th>
</tr>
<tr>
<td>'.$result['full_name'];'</td>
</tr>';
}
echo $output;
}
?>
Но он работает не так, как ожидалось.Когда я использую var_dump($result['full_name']);
, он сбрасывает все данные из базы данных, а когда я что-то ищу, он ничего не показывает ...