I’m trying to get the tag-it jquery plugin to work with a json string.
Currenttly i’m getting my values from the database like this:
$query = sprintf(
'SELECT
t.tag
FROM
tags AS t
');
$row_set= array();
if($result = mysqli_query($db, $query))
{
// fetch data
while ($row = mysqli_fetch_assoc($result))
{
$row_set[] = $row;
}
// set the output
echo json_encode($row_set);
}
which gives the following output when called in AJAX:
[{"tag":"test"},{"tag":"tests"}]
But I have to output a JSON string in the following format:
["android-intent","animate","architecture","artificial-intelligence","attributes"]
How can i achieve this?
When you use
row_set[] = $row;most likely$rowlooks like this$row['tag'] = 'testthat is why you are having JSON object format;Try
Make sure you also set the seound parameter to
trueto makeJSONalways return arrayThis would return the it as array not as a object