1
I have the following error to follow and can not solve:
Error:
Uncaught SyntaxError: Unexpected token ] in JSON at position 142
at JSON.parse (<anonymous>)
at XMLHttpRequest.xmlhttp.onreadystatechange (forma_pag_cad_controller.js:24)
The string is this result:
{"nome":"Dinheiro"}{"nome":"Cheque"}{"nome":"Cart\u00e3o - Cr\u00e9dito - VR Benef\u00edcios"}{"nome":"Cart\u00e3o Aura - Cr\u00e9dito"}
My code:
// LISTA FORMAS DE PAGAMENTO
$scope.formapag = [];
$scope.getformaspag = function () {
$scope.formapag = [];
$ionicLoading.show();
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var responseishere = xmlhttp.responseText;
if (responseishere == "error") {
$scope.nothing = 1;
$ionicLoading.hide();
$scope.$broadcast('scroll.refreshComplete');
} else {
$ionicLoading.hide();
var myobj = JSON.parse(responseishere);
for (var i = 0; i < myobj.length; i++) {
$scope.formapag.push(myobj[i]);
}
$scope.$broadcast('scroll.refreshComplete');
}
}
};
xmlhttp.open("GET", "http://vovocooks.com.br/admin/apis/vovo/cadastro_vovo/lista_formPag.php", true);
xmlhttp.send();
}
$scope.getformaspag();
I have changed the Json format, but still the error.
Does anyone know what it can be?
UPDATE: Follow my PHP:
<?php
header('Content-type: application/json; charset=utf-32"');
header('Access-Control-Allow-Origin: *');
include 'database.php';
//$cod_fornecedor=$_GET['cod_fornecedor'];
$query="SELECT
nome
FROM
formas_pagamento
ORDER BY
cod_forma_pagamento ASC";
$result=$con->query($query);
$row_cnt = mysqli_num_rows($result);
if ($result->num_rows > 0)
{
$count=0;
echo "[";
while($row = $result->fetch_assoc())
{
$count++;
echo json_encode($row);
if($count!=$row_cnt)
{
echo ",";
}
}
echo "]";
}
else
{
echo "error";
}
?>
Edit your question and ask
string
ofjson
who’s trying to parse– Sorack