Bonsoir à tous, je suis toujours sur la création d'un moteur de recherche sous React qui intéroge un script PHP. Mais il ne fait aucune proposition et la console n'indique aucune erreur.
Donc voici mon App.js

import React from 'react'
import Turnstone from 'turnstone'

const styles = {
input: 'border p-2 bg-white w-full',
listbox: 'border p-2 bg-white w-full'
}

// Set up listbox contents.
const listbox = {

data: (query) =>
fetch(http://essai/mr/query.php?query=${encodeURIComponent(query)})
.then(res => res.json())
}

export default function BasicExample() {
return <Turnstone id="autocomplete" listbox={listbox} styles={styles} typeahead={false} />
}

et voici mon script php

<?php

header('Access-Control-Allow-Origin: http://localhost:3000');

header("Content-Type: application/json");

$nbr = 0;

$data = array();

$liste = array();

//fetch.php
$connect = mysqli_connect("localhost", "root", "", "immoffre");
$output = '';

$name = $_GET['query'];

//fetch.php
$connect = mysqli_connect("localhost", "root", "", "immoffre");
$output = '';
if(isset($name))
{
$search = mysqli_real_escape_string($connect, $name);
$query = "
SELECT FROM villes_france
WHERE ville_nom LIKE '%" . $search . "%'
OR ville_slug LIKE '%" . $search . "%'
OR ville_code_postal LIKE '%" . $search . "%'
LIMIT 5
";
}
else
{
$query = "
SELECT
FROM tbl_customer ORDER BY CustomerID
";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{

while($row = mysqli_fetch_array($result))
{

$nbr++;
$data[$nbr]   =   $row["ville_nom"];

}

}

echo json_encode($data);

?>

Cordialement

Aucune réponse