// https://viblo.asia/p/cach-khac-phuc-loi-cors-policy-khi-goi-api-tu-frontend-gDVK23aeZLj
C:\Windows\System32>"C:\Program Files\Google\Chrome\Application\chrome.exe" --disable-web-security --disable-gpu --user-data-dir=~/chromeTemp
<?PHP
header('Access-Control-Allow-Origin: *');
?>
C:\Users\Administrator\AppData\Local\Temp\scp22717\home\admin\domains\yp.vn\public_html\phpjson.php
<?php
header('Content-type:application/json;charset=utf-8');
header('Access-Control-Allow-Origin: *');
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->build();
if (isset($_GET['keyword'])) {
$search = '{
"bool": {
"must": [
{
"multi_match": {
"query": "' . $_GET['keyword'] . '",
"type": "phrase",
"fields": [
"post_title^1",
"post_content^2",
"terms.pointfinderltypes.name^1",
"terms.ep_custom_result.name^9999"
]
}
}
]
}
}';
}
if (isset($_GET['coordinates']) && $_GET['sort'] == 1) {
$sort_by_coordinates =
'{
"_geo_distance" : {
"geo_point.location" : "' . $_GET['coordinates'] . '",
"order" : "asc",
"unit" : "km"
}
},
"_score"';
}
$filters = '{"match": {"post_type.raw": "listing"}}';
if (isset($_GET['listing'])) {
$filters .= ',{"match": {"post_id": ' . $_GET['listing'] . '}}';
}
if (isset($_GET['coordinates']) && (isset($_GET['range']))) {
$filters .=
',{
"geo_distance": {
"distance": "' . $_GET['range'] . 'km",
"geo_point.location": "' . $_GET['coordinates'] . '"
}
}';
}
if (isset($_GET['carrer'])) {
$filters .= ',{"term" : { "terms.pointfinderltypes.term_id" : ' . $_GET['carrer'] . '}}';
}
if (isset($_GET['location'])) {
$filters .= ',{"term" : { "terms.pointfinderlocations.term_id" : ' . $_GET['location'] . '}}';
}
if (isset($_GET['size'])) {
$page = '"size":' . $_GET['size'] . ',';
}
if (isset($_GET['from'])) {$page .= '"from":' . $_GET['from'] . ',';}
$query = json_decode('{' . $page . '"query": { "bool": { "must": [' . $search . '],"filter":[' . $filters . ']}},"sort": [' . $sort_by_coordinates . ']}', true);
$params = [
"index" => "ypvn-post-1",
"body" => json_encode($query),
];
$response = $client->search($params);
$titles = $response['hits']['hits'];
$alltitles = [];
foreach ($titles as $key => $title) {
$alltitles['alltitles'][] = $title['_source']['post_title'];
}
echo json_encode($alltitles);
?>
C:\xampp\htdocs\autocomplete\EasyAutocomplete-master\demo\example_categories.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>EasyAutocomplete categories</title>
<link href="../dist/easy-autocomplete.min.css" rel="stylesheet" type="text/css">
<link href="../dist/easy-autocomplete.themes.min.css" rel="stylesheet" type="text/css">
<link href='//fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic,600,600italic&subset=latin,cyrillic-ext,greek-ext,latin-ext,cyrillic'
rel='stylesheet' type='text/css'>
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
<script src="../dist/jquery.easy-autocomplete.min.js" type="text/javascript"></script>
</head>
<body>
<h1>EasyAutocomplete - categories example</h1>
<input id="data-categories" placeholder="Fruits and vegetables"/>
<script type="text/javascript">
var options = {
url: 'https://yp.vn/phpjson.php?size=9000',
categories: [{
listLocation: 'alltitles',
header: '--- FRUITS ---'
}],
list: {
match: {
enabled: false
},
maxNumberOfElements: 10
},
theme: 'dark'
};
$('#data-categories').easyAutocomplete(options);
</script>
</body>
</html>