I am working on a feature of my website where I need to trigger an ajax call on the click of button. I am receiving data in this format:
Object {
name: "abc",
category_id: "1"
}
I want a result like this:
{
"list" : [
{
"name" : "xyz",
"category_id" : "1"
}, {
"name" : "abc",
"category_id" : "11"
}
]
}
my server side code is:
<?php
header('Content-Type: application/json');
$conn = mysqli_connect("localhost","root","","test") or die(mysqli_error());
$name = $_GET['name'];
$sql = "SELECT * from test_search where name = '$name'";
$result = mysqli_query($conn,$sql) or die(mysqli_error($conn));
while($row = mysqli_fetch_array($result)) {
$name = $row['name'];
$category = $row['category_id'];
}
$data = array("name" => $name , "category_id" => $category );
echo json_encode($data);
?>