Es ist meine erste Zeit-Codierung mit JS & JSON & Ich habe eine Fehlermeldung, wenn ich getJSON verwendet:Parse Fehler JSON.parse bei der Verwendung von getJSON
parsererror
SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data
return window.JSON.parse(data);
Hier mein Code:
$.getJSON("../processeur.php",{
idProg: idp,
exercice: exo,
ajax: "true"})
.done(
function(response)
{
// alert("success");
var options ="";
if(response != null)
{
var length = response.data.length;
for(var i=0; i<length; i++)
{
options +="<option value = '"+response.data[i]+"'>"+response.data[i];"</option>";
}
}
$("#Liberation tbody").append
(
"<tr>"+
"<td align='center'><input class='liberationL' name='liberationL' type='text'/></td>"+
"<td align='center'><input class='serviceL' name='serviceL' type='text'/></td>"+
//liste déroulante des codes projets destinataires
"<td align='center'>"+"<select class='codest' name ='codest' id=listecodes >"+"<option>Aucun</option>"+options+"</select>"+"</td>"+
// "<td align='center'><input class='dateL' name='dateL' type='text'/><span><br>jj-mm-AAAA</span></td>"+
"<td align='center'><input type='text' class='dateL' id='DateF' name='dateL' onclick='javascript:onCalendar_click();'/></td>"+
"<td align='center'><input class='montantL' name='montantL' type='text'/></td>"+
//liste déroulante des types de mouvements
"<td align='center'>"+"<select class='mouvementL' name='mouvementL'>"+"<option value='lc'>LC(-)</option>"+"<option value='vc'>VC(+)</option>"+"<option value='ci'>CI</option>"+"</select>"+"</td>"+
"<td align='center'>"+
"<img src='../images/enregistrer.png' class='btnEnregistrerLiberation'"+"style='cursor: pointer;'/>"+' '+"<img src='../images/supprimer.png' class='btnSuppLiberation'"+"style='cursor: pointer;'/>"+"</td>"+
"</tr>");
$(".btnEnregistrerLiberation").bind("click",EnregistrerLiberation);
$(".btnSuppLiberation").bind("click",SupprimerLib);
})
.fail(function(jqxhr, textStatus, err){
alert("error : " + textStatus);
console.log(textStatus, err);
});
Hier mein PHP-Code:
include './BD/T_mouvements.php';
include '../sql.php';
require './jsonwrapper/jsonwrapper.php';
$idProg = $_GET['idProg'];
$exercice = $_GET['exercice'];
$array = array();
$liste = selectionnerListePro($exercice, $idProg);
//$liste = selectionnerListePro(2011, 4);
foreach ($liste as $item)
{
$array[] = array($item);
}
echo "{\"data\":". json_encode($array) . "}";
exit();
Und hier ist das Ergebnis meiner PHP-Code, wenn die Parameter ar e wählen manuell für die Funktion, die Abfrage ausgeführt wird (z.Bsp 2011 & 4):
{"data":[["DEV-SID"],["ENTREPOTDUI"],["HYDROGEOL"],["MES-TEMPS"],["MET-ENTREPO"],["MIG-BO\/XI"],["SID-AMODG"],["SID-ARCHID"],["SID-DSI"],["SID-FNGE"],["SID-OT-POL"],["SID-PILOTAG"],["SID-USAGRH"],["SIG-3D"],["SIG-ALTERNA"],["SIG-BDTOPO"],["SIG-CAO-DAO"],["SIG-DON-PDI"],["SIG-DONNEES"],["SIG-ORTHO"],["SIG-PLATGEO"],["SIG-STRUCTU"],["SIG-TOURNEE"],["SIG-WEB-PDI"],["STAT-CREDOC"]]}
Ich verstehe nicht, wo mein Fehler ist ..
http://json.parser.online.fr/ reduziert werden - das JSON ist nicht gültig - auch Ihre Paste hat ein verstecktes Zeichen in Vorderseite der Daten - Das gültige Objekt könnte wie folgt aussehen: {"data": ["DEV-SID", "ENTREPOTDUI", "HYDROGEOL", "MES-TEMPS", "MET-ENTREPO", "MIG-BO \ /" XI "," SID-AMODG "," SID-ARCHID "," SID-DSI "," SID-FNGE "," SID-OT-POL "," SID-PILOTAG "," SID-USAGRH "," SIG- 3D, SIG-ALTERNA, SIG-BDTOPO, SIG-CAO-DAO, SIG-DON-PDI, SIG-DONNEES, SIG-ORTHO, SIG-PLATGEO, SIG-STRUCTU "," SIG-TOURNEE "," SIG-W EB-PDI "," STAT-CREDOC "] }' – mplungjan
Warum? Wo habe ich einen Fehler gemacht? – LynxWeb
Sie können 'json_encode' für das gesamte Ergebnis verwenden. Etwas wie 'echo json_encode ([' data '=> $ array]); ' –